解决某些手机RadioGroup中的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" 都可以让按钮居中,两个使用其中之一就可以了。

居中后的截图:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值