解決某些手機RadioGroup中的RadioButton不置中問題

來源:互聯網
上載者:User

標籤:radiobutton   置中   

公司的一個項目,一直都在紅米1S上做介面,一天為了看下解析度適配,在一台中興U819上調試了下程式,結果發現原先置中對齊的底部欄按鈕,現在都向右位移了..大概如下:



布局是這麼寫的:

<?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="match_parent"    android:background="@color/app_base_bg"    android:orientation="horizontal" >    <RelativeLayout        android:layout_width="match_parent"        android:layout_height="match_parent"        android:background="#eeeeee" >        <include            android:id="@+id/id_ll_main_title"            layout="@layout/layout_base_title" />        <android.support.v4.view.ViewPager            android:id="@+id/id_vp_main"            android:layout_width="match_parent"            android:layout_height="match_parent"            android:layout_above="@+id/id_line_tab_top"            android:layout_below="@+id/id_ll_main_title" />        <View            android:id="@+id/id_line_tab_top"            android:layout_width="match_parent"            android:layout_height="1dp"            android:layout_above="@+id/id_ll_main_bottom"            android:background="@color/tab_line" />        <LinearLayout            android:id="@+id/id_ll_main_bottom"            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_alignParentBottom="true"            android:background="@color/white"            android:gravity="center"            android:orientation="horizontal" >            <RadioGroup                android:id="@+id/main_tab_group"                android:layout_width="match_parent"                android:layout_height="match_parent"                android:gravity="center"                android:orientation="horizontal"                android:paddingTop="2.0dip" >                <RadioButton                    android:id="@+id/id_rb_main_mine"                    android:layout_width="0dp"                    android:layout_height="wrap_content"                    android:layout_weight="1"                    android:button="@null"                    android:checked="true"                    android:drawableTop="@drawable/tab_btn_mine_selector"                    android:gravity="center"                    android:text="我"                    android:textColor="@color/tab_btn_text_color_selector"                    android:textSize="15sp" />                <RadioButton                    android:id="@+id/id_rb_main_discovery"                    android:layout_width="0dp"                    android:layout_height="wrap_content"                    android:layout_weight="1"                    android:button="@null"                    android:drawableTop="@drawable/tab_btn_discovery_selector"                    android:gravity="center"                    android:text="發現"                    android:textColor="@color/tab_btn_text_color_selector"                    android:textSize="15sp" />                <RadioButton                    android:id="@+id/id_rb_main_commend"                    android:layout_width="0dp"                    android:layout_height="wrap_content"                    android:layout_weight="1"                    android:button="@null"                    android:drawableTop="@drawable/tab_btn_commend_selector"                    android:gravity="center"                    android:text="推薦"                    android:textColor="@color/tab_btn_text_color_selector"                    android:textSize="15sp" />            </RadioGroup>        </LinearLayout>    </RelativeLayout></LinearLayout>
在紅米1S中一直都是置中顯示,而且在RadioButton中也使用了android:gravity="center"使其圖片文字置中,但在中興手機卻位移了,非常奇怪,難道是解析度問題,想想不可能吧..然後找了度娘才知道,參考:http://www.eoeandroid.com/thread-273181-1-1.html

網上說,只需要添加一個屬性:android:paddingLeft="0dp"就可以,還有人說設定下背景即可,自己試了下,在RadioButton中設定屬性android:paddingLeft="0dp"或者android:background="@color/transparent"都可以讓按鈕置中,兩個使用其中之一就可以了。

置中後的:









解決某些手機RadioGroup中的RadioButton不置中問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.