如何将一些 XML 元素包含在边界框中?

2024-02-22

我想在此处附上一对复选框和单选按钮:

...在矩形或“边界框”中,使其看起来像这样:

......当然,但不那么难看。如何以以下 XML 作为起点来做到这一点:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="hhs.app.SettingsActivity">

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="5dip"
        android:text="@string/select_your_printer"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <CheckBox
        android:id="@+id/ckbxNoPrinter"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/no_printer" />

    <CheckBox
        android:id="@+id/ckbxZebraQL220"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:checked="true"
        android:text="@string/zebra_ql220" />

    <Space
        android:layout_width="match_parent"
        android:layout_height="5dp" />

    . . .

    <RadioGroup
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <RadioButton
            android:id="@+id/radbtnBar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/using_labels_black" />

        <RadioButton
            android:id="@+id/radbtnPlain"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:text="@string/using_plain_labels" />
    </RadioGroup>

    <Space
        android:layout_width="match_parent"
        android:layout_height="2dp" />

    . . .
    </LinearLayout>

</LinearLayout>

?

UPDATE

我尝试应用 Der Golem 的建议,如下所示:

<LinearLayout 
    android:orientation="vertical"
    android:layout_width="wrap_content">
    <shape
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle"
        android:layout_width="wrap_content">
        <stroke
            android:width="4dp"
            android:color="#f000"
            android:layout_width="wrap_content" />
        <TextView
            android:text="@string/after_fetching_palabra"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            />
    </shape>
</LinearLayout>

...但这没有任何作用(好的); TextView 只是作为测试,从一个简单的小部件开始。

注意:这是 LinearLayout 中的 LinearLayout。当我删除它时,一切都很好,但是有了它,布局甚至不会渲染。

UPATE 2

所以我认为我将形状放在 \res\drawable 文件夹中。但在 Droidio 中,它给了我四个,数一下,四个可绘制文件夹,即:

drawable-hdpi
drawable-mdpi
drawable-xhdpi
drawable-xxhdpi

我需要将xml放入each这些文件夹,或者我可以创建一个“通用/默认”普通旧“可绘制”文件夹并将其放在那里吗?


使用一个垂直的 LinearLayout 来包围您的复选框,并使用另一个垂直的 LinearLayout 来包围您的单选按钮,并为它们分配一个 xml 可绘制对象作为背景(如果您觉得更舒服,您也可以使用 9 补丁):

两个额外的 LinearLayout 是外部容器的子级。

/res/drawable/box.xml(自包含 xml 可绘制):

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle"
    >
    <stroke
        android:width="4dp"
        android:color="#f000"
    />
</shape>

以供参考:http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape

[EDIT]

将 xml 可绘制对象应用为普通背景:

这只是两个布局之一:“CheckBox”:

...

<LinearLayout 
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/box"
    >
     <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="5dip"
        android:text="@string/select_your_printer"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <CheckBox
        android:id="@+id/ckbxNoPrinter"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/no_printer" />

    <CheckBox
        android:id="@+id/ckbxZebraQL220"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:checked="true"
        android:text="@string/zebra_ql220" />
</LinearLayout>

...

[EDIT 2]

现在有点题外话。
你要的是一个简单的方形盒子,没有别的东西,所以这就是我提供的。
但。在我提供的链接中详细显示了您如何(例如)不仅把角弄圆,还能给你的造型带来不一样的感觉背景颜色甚至是一个颜色渐变.
仅举几个可绘制形状的有趣属性。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何将一些 XML 元素包含在边界框中? 的相关文章

随机推荐

  • Blend KeyTrigger 多次触发

    我在 WPF 项目中使用 Blend SDK KeyTrigger 并且遇到这样的问题 每次按下指定的键 此处为 DeleteCommand 时 都会多次触发该事件
  • 灯塔中最大的内容油漆 (LCP) 是 p 标签。 (使用盖茨比)

    我不知道为什么我的 LCP 会是一个 p 标签 也不知道我会采取什么措施来减小它的大小 有时它会达到 2 6 秒并给出黄色评级 而不是绿色 这是 p 标签 所有这些类都是引导类 p aboutText p 这是变量aboutText con
  • 从现有矩阵中提取矩阵

    我编写了一段代码来生成一个四列矩阵 以获取总和等于 9 且每个数字从 0 到 9 变化的所有数字组合 m zeros 220 4 pd 9 i 1 for p 0 1 pd for q 0 1 pd p for a 0 1 pd q p m
  • 在 R igraph 中正确着色顶点

    我正在使用 igraph 给顶点着色 我有两个 CSV 文件答案和图表拓扑 答案 这表明玩家 K 和 N 回答正确 Player Q1 I1 1 k 1 2 l 0 3 n 1 4 m 0 拓扑 表示谁与谁相连 Node 1 Node 2
  • 使用 extraOptimizations 改造 Spark SQL AST

    我想将 SQL 字符串作为用户输入 然后在执行之前对其进行转换 特别是 我想修改顶级投影 select 子句 注入要由查询检索的附加列 我希望通过使用 Catalyst 来实现这一点sparkSession experimental ext
  • 如何使用 iframe 内的函数从父页面删除 iframe?

    我有一个使用书签放在页面上的 iframe 当我导航到此 iframe 内的某个页面时 我希望此 iframe 自行关闭 如何使用 JavaScript 做到这一点 注意 iframe 和容器页面位于不同的域中 据我所知 您无法从 ifra
  • Python:异步生成器已在运行

    如下例所示 我在使用异步生成器时遇到了异常错误 async def demo async def get data for i in range 5 loop for or while await asyncio sleep 1 some
  • Azure Web 应用程序与 Azure 移动应用程序

    我今天创建了一个Azure Web应用程序 它在设置中有一个移动部分 其中包含推送通知 移动身份验证等 您甚至可以下载移动客户端应用程序的源代码 我知道这曾经是移动应用程序 移动服务 的一部分 我创建了一个 Azure 移动应用程序来与 W
  • 识别活动网络接口

    在 NET 应用程序中 如何识别使用哪个网络接口与给定 IP 地址进行通信 我在具有多个网络接口 IPv4 和 v6 的工作站上运行 并且我需要获取用于流向给定数据库服务器的 正确 接口的地址 最简单的方法是 UdpClient u new
  • Allure Framework:TestNG 适配器错误地将 @AfterMethod 放置在报告中

    我正在使用 allure V1 4 8 TestNG 看起来 TestNG 适配器错误地将 AfterMethod 放置在报告中 基本上它将 AfterMethod 从测试用例放入下一个测试用例中 这是简单的代码 Step a test1
  • 从 .Net 应用程序打开 Windows 7 帮助 (helpPane.exe)

    我正在尝试从 Net 表单应用程序打开 Windows 7 帮助到特定书签 例如在打印机安装时 我尝试以与打开控制面板小程序相同的方式打开它 在下面的示例中返回和恢复 ProcessStartInfo startInfo new Proce
  • 当页面滚动到顶部时,Next.js 链接不会呈现

    我有一个像这样的组件 const Milestone props gt const path disabled index rest props if disabled return
  • 生成一定范围内的唯一随机数

    我需要在一定范围内生成随机的唯一数字 我该怎么做 我可以通过以下方式生成随机数 generator arr x rand min max len count arr flag 0 for i 0 i lt len i if flag 1 g
  • 如何在javascript中打印所有百分比超过70%的学生姓名?

    我在用json rule engine https www npmjs com package json rules engine https www npmjs com package json rules engine我有一份学生名单
  • 在 R 中向量化循环

    必须有一种简单的方法来向量化 R 中的以下循环 但我看不到它 w lt numeric 10 z lt rnorm 20 v lt c sample 1 10 10 sample 1 10 10 Random ordering of c 1
  • jQuery AJAX 提交表单

    我有一张带有姓名的表格orderproductForm以及未定义数量的输入 我想做某种 jQuery get 或 ajax 或类似的东西 通过 Ajax 调用页面 并发送表单的所有输入orderproductForm 我想一种方法是做类似的
  • pyside-uic 在哪里?

    我正在尝试使用 Qt Designer 和 pyside uic mydesign ui gt design py 但是 这个程序不存在 我查看了 python 2 7 下的站点包 我看到 pyside lupdate exe pyside
  • 创建项目后如何将 ndk 设置从默认 C++ 工具链更改为 C++14?

    我使用默认的 C 工具链创建了一个 Android 项目 现在 当我尝试包含双簧管上包含 C 14 功能的示例项目的代码片段时 我不断收到错误 因此 我尝试包含代码来创建模板 但现在它使我的代码变得混乱 并转储了我不希望有的声明 我尝试提及
  • 使用 Meteor.settings 功能

    Meteor 最近添加了一个全新的Meteor 设置 http docs meteor com meteor settings meteor settings对象从 v0 5 4 开始 并且以一种极其烦人的方式 没有在他们的文档中正确解释如
  • 如何将一些 XML 元素包含在边界框中?

    我想在此处附上一对复选框和单选按钮 在矩形或 边界框 中 使其看起来像这样 当然 但不那么难看 如何以以下 XML 作为起点来做到这一点