2013-12-09 186 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