我的布局中有一个 AppCompatCheckBox。这是它的样子:
问题是填充或边距或重力不是我想要的方式。 Box 和左边框之间有一个小间隙。我将 gravity 设置为 left/start padding 和 margin 为 0,但差距仍然存在。我怎样才能删除它?我希望它完全位于左边界或居中。两者都会好起来的。但是将重力设置为中心也不起作用。
有人有想法吗?
CheckBox 和 Text 应该在彼此之上。
<LinearLayout
android:id="@+id/llRoot"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/llCbs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.v7.widget.AppCompatCheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="?attr/textColor" />
<android.support.v7.widget.AppCompatCheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="?attr/textColor" />
<android.support.v7.widget.AppCompatCheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="?attr/textColor" />
</LinearLayout>
<LinearLayout
android:id="@+id/llTv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
最佳答案
将复选框 minWidth
和 minHeight
值设置为零
checkbox.setMinWidth(0);
checkbox.setMinHeight(0);
或通过 xml
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="0dp"
android:minHeight="0dp" />
关于Android AppCompatCheckbox 填充/边距/重力,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40990664/