解决某些手机RadioGroup中的RadioButton不居中问题
2015-06-11 10:17
585 查看
公司的一个项目,一直都在红米1S上做界面,一天为了看下分辨率适配,在一台中兴U819上调试了下程序,结果发现原先居中对齐的底部栏按钮,现在都向右偏移了..截图大概如下:
![](https://oscdn.geek-share.com/Uploads/Images/Content/202002/14/340cdce4dfe8f37e10a0cf8328bbee1b.jpg)
布局是这么写的:
在红米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" 都可以让按钮居中,两个使用其中之一就可以了。
居中后的截图:
![](https://oscdn.geek-share.com/Uploads/Images/Content/202002/14/340cdce4dfe8f37e10a0cf8328bbee1b.jpg)
布局是这么写的:
<?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" 都可以让按钮居中,两个使用其中之一就可以了。
居中后的截图:
![](https://oscdn.geek-share.com/Uploads/Images/Content/202002/14/bf7af675c83ca7ebdb84fa6b222a7d07.jpg)
相关文章推荐
- Flex4 DataGrid中嵌入RadioButton实现思路及代码
- c# 如何将RadioButton与DataTable数据进行绑定
- jquery判断RadioButtonList和RadioButton中是否有选中项示例
- android自定义RadioGroup可以添加多种布局的实现方法
- android RadioButton和CheckBox组件的使用方法
- Asp.Net如何将多个RadioButton指定在一个组中
- Android控件系列之RadioButton与RadioGroup使用方法
- 自定义RadioButton和ViewPager实现TabHost带滑动的页卡效果
- Android中设置RadioButton在文字右边的方法实例
- ASP.NET单选按钮控件RadioButton常用属性和方法介绍
- 如何通过LayoutInflater,得到多个RadioButton
- 关于RadioGroup的xml文件
- 去掉radioGroup的图标
- 设置ToggleButton、Switch、CheckBox和RadioButton的显示效果
- 设置ToggleButton、Switch、CheckBox和RadioButton的显示效果
- [转摘]jQuery formValidator表单验证插件开源了!!含API帮助、源码、示例
- PagedCollectionView
- 项目撰写规范
- 项目撰写规范
- Android 自定义RadioButton或CheckBox选择样式