2014-01-09 28 views
3

我有一個有RadioGroup和單選按鈕的佈局。它的工作原理,但在顯示方面存在問題。我已經分享了下面的截圖。Android - 無線組按鈕文本位置

的Android 4.2.1 - 4.65英寸
Android 4.2.1 - 4.65 inch

平板的Android 2.2 - 7英寸
Tablet Android 2.2 - 7 inch

的Android 4.1.2 - 5.5英寸
Android 4.1.2 - 5.5 inch

從bottorbar代碼佈局

從主要佈局
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" android:layout_height="wrap_content" 
    android:padding="3dp" android:gravity="center" 
    android:background="@drawable/bottom" 
    > 

    <RadioGroup 
     android:id="@+id/radioTur" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:measureWithLargestChild="true" 
     android:layout_gravity="center_vertical" 
     android:orientation="horizontal" > 

     <RadioButton 
    android:id="@+id/rad_anasayfa" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:textAppearance="?android:attr/textAppearanceSmall" 
    android:button="@null" 
    android:gravity="center" 
    android:drawableTop="@drawable/anasayfabutton" 
    android:textColor="@color/White" 
    android:onClick="Anasayfa_TIKLA" 
    android:text="Anasayfa" > 
    </RadioButton> 

     <RadioButton 
    android:id="@+id/rad_haber" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:button="@null" 
    android:gravity="center" 
    android:layout_weight="1" 
    android:textAppearance="?android:attr/textAppearanceSmall" 
    android:drawableTop="@drawable/haberlerbutton" 
    android:textColor="@color/White" 
    android:onClick="Haber_TIKLA" 
    android:text="Haberler" > 
    </RadioButton> 

     <RadioButton 
    android:id="@+id/rad_duyuru" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:button="@null" 
    android:gravity="center" 
    android:layout_weight="1" 
    android:textAppearance="?android:attr/textAppearanceSmall" 
    android:drawableTop="@drawable/duyurubutton" 
    android:textColor="@color/White" 
    android:onClick="Duyuru_TIKLA" 
    android:text="Duyurular" > 
    </RadioButton> 

      <RadioButton 
    android:id="@+id/rad_yemek" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:button="@null" 
    android:gravity="center" 
    android:layout_weight="1" 
    android:textAppearance="?android:attr/textAppearanceSmall" 
    android:drawableTop="@drawable/yemekbutton" 
    android:textColor="@color/White" 
    android:onClick="Yemek_TIKLA" 
    android:text="Yemek" > 
    </RadioButton> 

      <RadioButton 
    android:id="@+id/rad_search" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:button="@null" 
    android:gravity="center" 
    android:layout_weight="1" 
    android:onClick="Arama_TIKLA" 
    android:textAppearance="?android:attr/textAppearanceSmall" 
    android:drawableTop="@drawable/search_icon" 
    android:textColor="@color/White" 
    android:text="Arama" > 
    </RadioButton> 

</RadioGroup> 
</LinearLayout> 

代碼

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:id="@+id/AnaLayout" 
    > 
<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/linearLayout1" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" > 

    <include 
     android:id="@+id/cell1" 
     android:layout_height="wrap_content" 
     layout="@layout/bottombar" 
     /> 
</LinearLayout> 
</RelativeLayout> 

我已經工作了幾days.I不明白的問題。有人能幫我嗎 ?

my icon 我的圖標

+0

對於RadioButton,使用android:layout_width =「wrap_content」。 –

+0

感謝您的快速評論,但它無法正常工作。 –

+0

@CanerBalım看看我的答案。 – GrIsHu

回答

3

我發現問題了。問題是android:button =「@ null」。

如果radiobutton具有android:button =「@ null」屬性; 結果: enter image description here

如果單選按鈕還沒有安卓按鈕= 「@空」 屬性; 結果: enter image description here

如果單選按鈕具有機器人:按鈕= 「@空」 和機器人:背景= 「@android:彩色/透明」 屬性 結果: enter image description here

我加入機器人:background =「@android:color/transparent」propery every radiobutton and Problem was solved。

+0

當我設置android:button =「@ null」時,單選按鈕沒有被檢查(點擊)。我做錯了什麼。請幫助http://stackoverflow.com/questions/28052820/android-custom-radio-button-not-getting-checked –

0

試試這個..

更改RadioGroup寬度match_parent和嘗試。

<RadioGroup 
     android:id="@+id/radioTur" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:measureWithLargestChild="true" 
     android:layout_gravity="center_vertical" 
     android:orientation="horizontal" > 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/linearLayout1" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" > 

    <include 
     android:id="@+id/cell1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     layout="@layout/bottombar" 
     /> 
</LinearLayout> 

enter image description here

這裏是我完整的代碼

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center" 
    android:padding="3dp" > 

    <RadioGroup 
     android:id="@+id/radioTur" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_vertical" 
     android:measureWithLargestChild="true" 
     android:orientation="horizontal" > 

     <RadioButton 
      android:id="@+id/rad_anasayfa" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:button="@null" 
      android:drawableTop="@drawable/uP13v" 
      android:gravity="center" 
      android:onClick="Anasayfa_TIKLA" 
      android:text="Anasayfa" 
      android:textAppearance="?android:attr/textAppearanceSmall" > 
     </RadioButton> 

     <RadioButton 
      android:id="@+id/rad_haber" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:button="@null" 
      android:drawableTop="@drawable/uP13v" 
      android:gravity="center" 
      android:onClick="Haber_TIKLA" 
      android:text="Haberler" 
      android:textAppearance="?android:attr/textAppearanceSmall" > 
     </RadioButton> 

     <RadioButton 
      android:id="@+id/rad_duyuru" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:button="@null" 
      android:drawableTop="@drawable/uP13v" 
      android:gravity="center" 
      android:onClick="Duyuru_TIKLA" 
      android:text="Duyurular" 
      android:textAppearance="?android:attr/textAppearanceSmall" > 
     </RadioButton> 

     <RadioButton 
      android:id="@+id/rad_yemek" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:button="@null" 
      android:drawableTop="@drawable/uP13v" 
      android:gravity="center" 
      android:onClick="Yemek_TIKLA" 
      android:text="Yemek" 
      android:textAppearance="?android:attr/textAppearanceSmall" > 
     </RadioButton> 

     <RadioButton 
      android:id="@+id/rad_search" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:button="@null" 
      android:drawableTop="@drawable/uP13v" 
      android:gravity="center" 
      android:onClick="Arama_TIKLA" 
      android:text="Arama" 
      android:textAppearance="?android:attr/textAppearanceSmall" > 
     </RadioButton> 
    </RadioGroup> 

</LinearLayout> 
+0

感謝上次孩子的文字問題解決。但其他人沒有改變。 –

+0

@CanerBalım將'RadioButton'的寬度更改爲'android:layout_width =「0dp」'並且還添加了'android:singleLine =「true」' – Hariharan

+0

謝謝。多行消失,但文本看起來像這樣 安娜...哈布... Duy ... Yem ...阿拉馬 –

0

嘗試下面的佈局。 我已經爲所有RadioButton分配了相同的權重,以便根據屏幕大小調整其大小。 現在工作正常。改變你的形象accroding給你。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/aa" 
    android:gravity="center" 
    android:padding="3dp" 
    android:weightSum="1" > 

    <RadioGroup 
     android:id="@+id/radioTur" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

     <RadioButton 
      android:id="@+id/rad_anasayfa" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight=".2" 
      android:button="@null" 
      android:gravity="center" 
      android:drawableTop="@drawable/ic_circle" 
      android:onClick="Anasayfa_TIKLA" 
      android:text="Anasayfa" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:textColor="@android:color/white" > 
     </RadioButton> 

     <RadioButton 
      android:id="@+id/rad_haber" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight=".2" 
      android:button="@null" 
      android:drawableTop="@drawable/ic_circle" 
      android:gravity="center" 
      android:onClick="Haber_TIKLA" 
      android:text="Haberler" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:textColor="@android:color/white" > 
     </RadioButton> 

     <RadioButton 
      android:id="@+id/rad_duyuru" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight=".2" 
      android:button="@null" 
      android:drawableTop="@drawable/ic_circle" 
      android:gravity="center" 
      android:onClick="Duyuru_TIKLA" 
      android:text="Duyurular" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:textColor="@android:color/white" > 
     </RadioButton> 

     <RadioButton 
      android:id="@+id/rad_yemek" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight=".2" 
      android:button="@null" 
      android:drawableTop="@drawable/ic_circle" 
      android:gravity="center" 
      android:onClick="Yemek_TIKLA" 
      android:text="Yemek" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:textColor="@android:color/white" > 
     </RadioButton> 

     <RadioButton 
      android:id="@+id/rad_search" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight=".2" 
      android:button="@null" 
      android:drawableTop="@drawable/ic_circle" 
      android:gravity="center" 
      android:onClick="Arama_TIKLA" 
      android:text="Arama" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:textColor="@android:color/white" > 
     </RadioButton> 
    </RadioGroup> 

</LinearLayout> 
+0

謝謝,但無法正常工作。它看起來像第二張照片。但最後孩子的文字有所改善。 –

+0

在我身邊看起來很完美。 @CanerBalım在你的第一個'RadioButton'中添加'android:gravity =「center」'行並檢查。 – GrIsHu

+0

謝謝,但不工作的Android 2.2平板電腦。爲什麼添加radioGroup-text和radioGroup-android:drawableTop屬性? –