2013-12-09 105 views
1

任何人都可以解释我为什么会发生这种情况? 我有3个单选按钮和3个不同的图像。对于每个单选按钮,我创建了一个带有选择器的drawable,当单选按钮被选中时,它不是。它在日食中完美运行,但在模拟器上它可以很好地工作。单选按钮android

这是图像。

基于Eclipse:

On eclipse

在仿真器:

On Emulator

下面的代码:

<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> 

可抽拉:

<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> 

谁能帮助我?

+0

究竟什么叫“它不能很好地工作”是什么意思? –

+0

它不工作,因为当在模拟器上运行应用程序时,它将单选按钮的图像裁减了一半。我上传了模拟器的图片 – Short

+0

看来您的布局已被其他视图推出,它更小,减肥一些如何。 我想说,你没有发布包含radiogroup的整个XML文件。 ?您是否以编程方式设置视图的大小? –

回答

0
+0

我有不同的每个drawable的dpi图像。对于每个图像我有一个320dpi的版本,一个240dpi的版本和一个160dpi的版本,但它仍然可以工作... – Short

+0

单选按钮的图像大小是否有限? – Short

+0

确保您为每个DPI(hdpi,ldpi,mdpi,xhdpi,xxhdpi)创建了目录。之后,验证您的仿真器DPI。 – aterribili

0

我不明白为什么会这样,但如果我把一些文字它的工作原理,但与文本behing的单选按钮。

此代码:

<RadioButton 
    android:id="@+id/radioButtonSmallBag" 
    style="@style/radioButtonStyle" 
    android:checked="true" 
    android:button="@drawable/small_bag_selector"/> 

导致了这一点:

wrong

但是这个代码:

<RadioButton 
    android:id="@+id/radioButtonSmallBag" 
    style="@style/radioButtonStyle" 
    android:checked="true" 
    android:button="@drawable/small_bag_selector" 
    android:text="hiiiiiii"/> 

导致:

almost correct

这就是为什么我认为单选按钮具有极限尺寸。所以我有这个疯狂的想法,我做到了这一点:

<RadioButton 
    android:id="@+id/radioButtonSmallBag" 
    style="@style/radioButtonStyle" 
    android:checked="true" 
    android:background="@drawable/small_bag_selector" 
    android:button="@null"/> 

它的工作和做我想做的。 这就是:

correct