我想我没有在我的一个布局中看到错误。我想显示一个复选框和它周围的边框。
我使用Android Holo Colors Generator生成图像
我试图在复选框中添加一个形状,在Nexus4上运行良好,但在任何其他设备上都没有显示该按钮,因此我添加了一个虚拟布局:
布局:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5sp"
android:layout_marginTop="3sp"
android:background="@drawable/shape_button" >
<CheckBox
android:id="@+id/check"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:button="@drawable/btn_radio_holo_dark_hm" />
</LinearLayout>
形状:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@android:color/transparent"/>
<stroke
android:width="1px"
android:color="@color/gray" />
<corners
android:bottomLeftRadius="5sp"
android:bottomRightRadius="5sp"
android:topLeftRadius="5sp"
android:topRightRadius="5sp" />
</shape>
现在我明白了:
我试着根据mdpi/hdpi/xhdpi设置minwidth,但是这个按钮看起来从来没有在每个设备上居中。填充父/换行内容不会导致任何更改,也会在布局中移动按钮。
有什么问题的建议吗?
最佳答案
将外部布局更改为RelativeLayout并将CenterInParent设置为true for复选框
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5sp"
android:layout_marginTop="3sp"
android:background="@drawable/shape_button"
android:padding="2sp">
<CheckBox
android:id="@+id/check"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:button="@drawable/btn_radio_holo_dark_hm"
android:layout_centerInParent="true/>
</RelativeLayout>