Android AppCompatCheckbox 填充/边距/重力

标签 android android-layout android-appcompat

我的布局中有一个 AppCompatCheckBox。这是它的样子:

enter image description here

问题是填充或边距或重力不是我想要的方式。 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>

最佳答案

将复选框 minWidthminHeight 值设置为零

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/

相关文章:

Android - 无法打开模拟器窗口

java - android studio项目中没有菜单文件夹

android - 按钮布局有 4 个独立的 "borders": Can't get text in center

android - 使用 appcompat v21 将 TextView 设置为 Spinner

安卓 GTM : Possible to start new Google Analytics session manually?

java - 将 PreferenceScreen 添加到线性布局

Android - 能够在没有支持库的情况下使用 AppCompatActivity

android - Google Play 报告不支持的 API 但它在 AppCompat 中

java - 在 Eclipse AVD 中,我得到了 'Unfortunately ~ has stopped working'

android - Appcompat Alert Dialog Action 按钮背景 On pressed state