您的位置:首页 > 其它

解决某些手机RadioGroup中的RadioButton不居中(右移)问题

2015-08-23 21:31 525 查看
最近一直在忙一个项目,页面的基本框架类似于QQ那样,有底部导航栏的,遂采用的是RadioButton来实现的。本来一直在我的模拟器上测试,页面展示是没啥问题的,效果图如下:



可是,坑爹的事今天却发生了。 测试人员给我说,底部的导航栏图标文字右移,不居中,我的个擦,我一看,心中蹦出了一个鲜亮的词——尼玛,这是啥情况?!右移的图如下:



看看,这就是那个坑爹的效果啊。当然,坑爹归坑爹,还得解决啊,遂求助于度娘,发现,居然还有不少人遇到过这个问题,好心人给出了解决方案,只需要在每个RadioButton中,添加一个属性android:paddingLeft="0dp",或者是 android:background="@color/transparent" ,两个方案都可以ok的。

下面给出解决后的布局代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/activity_bg"
android:orientation="vertical">

<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1.0"></FrameLayout>

<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<RadioGroup
android:id="@+id/radiogroup"
android:layout_width="match_parent"
android:layout_height="50dip"
android:layout_gravity="bottom"
android:background="#ffffff"
android:gravity="center_vertical"
android:orientation="horizontal">

<RadioButton
style="@style/navigation_style"
android:checked="true"
android:drawablePadding="3dp"
android:drawableTop="@drawable/selector_main_bottom_tab_first"
android:paddingLeft="0dp"
android:text="首页" />

<RadioButton
style="@style/navigation_style"
android:checked="false"
android:drawablePadding="3dp"
android:drawableTop="@drawable/selector_main_bottom_tab_second"
android:paddingLeft="0dp"
android:text="唱歌" />

<RadioButton
style="@style/navigation_style"
android:checked="false"
android:drawablePadding="3dp"
android:drawableTop="@drawable/selector_main_bottom_tab_third"
android:paddingLeft="0dp"
android:text="跳舞" />

<RadioButton
style="@style/navigation_style"
android:checked="false"
android:drawablePadding="3dp"
android:drawableTop="@drawable/selector_main_bottom_tab_forth"
android:paddingLeft="0dp"
android:text="我的" />
</RadioGroup>
</RelativeLayout>
</LinearLayout>

</RelativeLayout>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: