Android 单选按钮安卓
谁能解释一下为什么会这样? 我有3个单选按钮和3个不同的图像。对于每个单选按钮,我都创建了一个带有选择器的可绘制按钮,用于选择单选按钮何时选中以及何时不选中。它在eclipse上工作得很好,但在模拟器上工作得不好 这是图片 在eclipse上: 在模拟器上: 代码如下:Android 单选按钮安卓,android,radio-button,drawable,Android,Radio Button,Drawable,谁能解释一下为什么会这样? 我有3个单选按钮和3个不同的图像。对于每个单选按钮,我都创建了一个带有选择器的可绘制按钮,用于选择单选按钮何时选中以及何时不选中。它在eclipse上工作得很好,但在模拟器上工作得不好 这是图片 在eclipse上: 在模拟器上: 代码如下: <RadioGroup android:id="@+id/radioGroup2" android:layout_width="match_parent" android:layout_heig
<RadioGroup
android:id="@+id/radioGroup2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/radioButtonSmallBag"
style="@style/radioButtonStyle"
android:checked="true"
android:button="@drawable/small_bag_selector"/>
<RadioButton
android:id="@+id/radioButtonMediumBag"
style="@style/radioButtonStyle"
android:button="@drawable/medium_bag_selector" />
<RadioButton
android:id="@+id/radioButtonBigBag"
style="@style/radioButtonStyle"
android:button="@drawable/big_bag_selector" />
</RadioGroup>
风格:
<style name="radioButtonStyle">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginLeft">5dp</item>
<item name="android:layout_marginRight">5dp</item>
</style>
包装内容
包装内容
5dp
5dp
可抽出式:
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:state_checked="true"
android:drawable="@drawable/trip_small_bag_selected"/>
<item
android:state_checked="false"
android:drawable="@drawable/trip_small_bag"/>
</selector>
有人能帮我吗?看看这个关于决心的答案:
支持多屏幕:您可能正在使用不同的
DPI
运行模拟器。您应该在不同的DPI
屏幕上提供不同的图像大小,例如,在MDPI
手机上,您可能需要使用图像,比如说,100x100 px
。然后,相同的图像转到HDPI
,但位于175x175 px
。然后对于HDPI
您选择200x200 px
。阅读更多信息我不明白为什么会发生这种情况,但如果我在单选按钮后面加上一些文字,它就会起作用
此代码:
<RadioButton
android:id="@+id/radioButtonSmallBag"
style="@style/radioButtonStyle"
android:checked="true"
android:button="@drawable/small_bag_selector"/>
结果是:
但是这个代码:
<RadioButton
android:id="@+id/radioButtonSmallBag"
style="@style/radioButtonStyle"
android:checked="true"
android:button="@drawable/small_bag_selector"
android:text="hiiiiiii"/>
导致:
这就是为什么我认为单选按钮有一个限制大小。所以我有了一个疯狂的想法,我做到了:
<RadioButton
android:id="@+id/radioButtonSmallBag"
style="@style/radioButtonStyle"
android:checked="true"
android:background="@drawable/small_bag_selector"
android:button="@null"/>
它在工作,做我想做的事。
这是:
你所说的“它不好用”到底是什么意思?它不好用,因为在模拟器上运行应用程序时,它会将单选按钮的图像减少一半。我上传了模拟器的图片。看起来你的布局被其他视图推掉了,使它变小了,减轻了一些重量。我想说的是,您没有发布包含radiogroup的整个XML文件?您是否以编程方式设置视图的大小?我有每个可绘制视图的不同dpi图像。对于每个图像,我有一个320dpi版本、一个240dpi版本和一个160dpi版本,但它仍然不起作用……单选按钮对图像的大小是否有限制?请确保为每个DPI(hdpi、ldpi、mdpi、xhdpi、xxhdpi)创建了目录。之后,验证仿真程序DPI。