- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有一个自定义单选按钮,其背景为 9 色补丁图像。我使用选择器来确定背景。我还有一些文字想放在图片的背景上,但文字在按钮旁边对齐。
这是广播组
<LinearLayout
android:id="@+id/segmented"
android:layout_width="fill_parent"
android:layout_height="50sp"
android:gravity="center"
android:layout_below="@+id/header">
<RadioGroup android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/group1"
android:gravity="center">
<RadioButton
android:checked="false"
android:layout_width="90sp"
android:id="@+id/rbVerzekeringen"
android:text="Verzekeringen"
android:textSize="10sp"
android:button="@drawable/checkbox_theme" />
<RadioButton
android:checked="false"
android:layout_width="90sp"
android:id="@+id/rbPersoonlijk"
android:text="Persoonlijk"
android:textSize="10sp"
android:button="@drawable/checkbox_theme" />
<RadioButton
android:checked="false"
android:layout_width="90sp"
android:id="@+id/rbNotities"
android:text="Notities"
android:textSize="10sp"
android:button="@drawable/checkbox_theme" />
</RadioGroup>
</LinearLayout>
这是选择器:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:state_window_focused="false"
android:drawable="@drawable/bt_filter_active" />
<item android:state_checked="false" android:state_window_focused="false"
android:drawable="@drawable/bt_filter" />
<item android:state_checked="true" android:state_pressed="true"
android:drawable="@drawable/bt_filter_active" />
<item android:state_checked="false" android:state_pressed="true"
android:drawable="@drawable/bt_filter" />
<item android:state_checked="true" android:state_focused="true"
android:drawable="@drawable/bt_filter_active" />
<item android:state_checked="false" android:state_focused="true"
android:drawable="@drawable/bt_filter" />
<item android:state_checked="false" android:drawable="@drawable/bt_filter" />
<item android:state_checked="true" android:drawable="@drawable/bt_filter_active" />
</selector>
这就是它的样子:
如您所见,我想要 3 个上面有文字的大按钮。
我该怎么做?
编辑:
我将选择器设置为背景而不是按钮,并将按钮设置为空。
代码现在看起来像这样:
<LinearLayout
android:id="@+id/segmented"
android:layout_width="fill_parent"
android:layout_height="50sp"
android:gravity="center"
android:layout_below="@+id/header">
<RadioGroup android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/group1"
android:gravity="center">
<RadioButton
android:checked="false"
android:layout_width="100sp"
android:layout_height="40sp"
android:id="@+id/rbVerzekeringen"
android:text="Verzekeringen"
android:textSize="13sp"
android:orientation="vertical"
android:background="@drawable/checkbox_theme"
android:button="@null"
android:gravity="center"/>
<RadioButton
android:checked="false"
android:layout_width="100sp"
android:layout_height="35sp"
android:id="@+id/rbPersoonlijk"
android:text="Persoonlijk"
android:textSize="35sp"
android:background="@drawable/checkbox_theme"
android:button="@null"
android:gravity="center"/>
<RadioButton
android:checked="false"
android:layout_width="100sp"
android:layout_height="30sp"
android:id="@+id/rbNotities"
android:text="Notities"
android:textSize="13sp"
android:background="@drawable/checkbox_theme"
android:button="@null"
android:gravity="center"/>
</RadioGroup>
</LinearLayout>
但是现在当我把按钮变大或变小时,里面的文字就这样消失了(第一张图片的高度是 40sp,第二张是 35sp,最后一张是 30sp):
如何在不剪切背景图片的情况下缩小背景图片?
最佳答案
您是否尝试将可绘制对象设置为 android:background 而不是按钮?
参见 here .
编辑:
我不确定,但我认为这取决于 9-patch 内容区域(底部和右边缘线),如果将 9-patch 设置为背景,Android 将基于此设置填充。内容区域随图像一起拉伸(stretch)。
关于android - 自定义 RadioButton 图像未填充空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4681902/
我一直在尝试使用 RadioButton 将另一个 RadioButton 变为可见。我是这个环境的新手,这是我的第一个 Windows Phone 应用程序。我的代码: private void
我有一个 GroupBox 和一堆 RadioButtons。当他们有焦点时,我可以使用向上/向下键来遍历它们。 但是,当我手动更改已选中的 RadioButton 并按向上/向下键时,迭代将从更改已
使用 WPF 和 MVVM 模式,我得到了一个动态填充单选按钮的列表框。
我有一个带有四个单选按钮的 RadioGroup,我让它们使用 4 的权重和在屏幕上均匀地隔开它们。这很好用,但结果是图形左对齐,而不是在每个单选按钮的中心。有没有办法将图形移动到中心?我尝试了重力中
我有 3 个单选按钮,用于对 API 中的不同数据进行排序。在每个单选按钮上,如果我按另一个单选按钮,单选按钮值就会消失,如下所示: 和 。我尝试使用属性绑定(bind) [value],但这导致了错
假设我有几个单选按钮和一些自定义对象作为数据源。 举个例子 public enum SomeModeType { firstMode = 10, secondMode = 20,
我正在尝试设置对单选组中第一个单选按钮的选择。在深入探讨这个问题之前,我需要指出问题仅发生在 API <= 16 中。当在模拟器或真实设备中运行 API 17 或更高版本时,一切正常。 它应该做什么
对于android编程,我有一个RadioGroup,其中包含一些RadioButtons。我只想从按钮获取文本,而不需要获取 RadioButton 的 id。
我编写了以下脚本,一旦单击要取消选中的其他复选框,它的工作正常,但是一旦我单击 tabkey,它就不会被选中或取消选中,它只会获得焦点, 脚本 function toggle(obj) { i
我有一个单选组,我可以在其中以编程方式添加单选按钮。这一切都是在 onCreateView() 方法中完成的,因此每次从后台堆栈重新创建 fragment 时都应该重做。我遇到的问题是,当我在开始时使
假设我在 RadioButtonGroup 中有一些 RadioButton。我单击其中一个,我意识到我不应该提交表单,相反,我只想触发取消操作并返回到我未选择的原始状态。我该怎么做? 最佳答案 想通
在我的布局中,我有一个 AppCompatRadioButton。使用 app:buttonTint 我将按钮设置为白色。如果我检查了 AppCompatRadioButton,圆圈的填充颜色也是白色
我正在开始使用 JavaFX,并且我已经构建了一个小俄罗斯方 block 游戏。现在一切正常,但最后我决定添加一组单选按钮来选择难度 - 这里我遇到了一个问题:突然LEFT/RIGHT/UP/DOWN
我的 RadioGroup 中的 RadioButton 在我取消选中它们或单击组中的另一个 RadioButton 后留下一个黑色的选中圆圈。我该如何防止这种情况发生?
在每个场景中,我都有多个切换组,每个切换组有两个单选按钮。无论我首先选择哪个场景上的哪个 RadioButton,听众都不会明白。它仍然为空,而不是保存设置的用户数据。如果我按第二次,它就会起作用。
我有一个有 2 个字段的应用程序:company_name 和 logo,我在 Model 的 Form 中显示像单选按钮这样的公司,但我想显示 logo 公司而不是公司标签(公司名称) 任何的想法
所以我想在我的应用程序中添加一个计算器。用户将首先单击适用于英制和公制单位的 RadioButton,然后根据用户单击的单选按钮,将出现其中一种布局。 如您所知,英制单位有英尺和英寸,为此我需要两个
我正在开发一个订单应用程序。如果实际时间在开放时间,则应将 rdi_now 的可见性设置为可见,否则设置为消失,因此用户在关闭时间只有选择预购的选项,但 rdi_preorder 没有做应该做的事情。
我在尝试单击时检查和取消选中单选按钮时遇到了一些问题。 我想做的是,当加载 Activity 时,单选按钮默认设置为选中。当用户按下选中的单选按钮时,我将单选按钮设置为取消选中并清空 TextView
我有三个单选按钮,我希望根据我单击的复选框上传我的 GUI。 我引用过本指南:http://docs.oracle.com/javafx/2/ui_controls/radio-button.htm这
我是一名优秀的程序员,十分优秀!