Android 带有多行文本的复选框

Android 带有多行文本的复选框,android,android-layout,android-checkbox,Android,Android Layout,Android Checkbox,我想将顶部的复选框与两行文本对齐。我希望复选框和文本在顶部的同一行中 注意:我尝试了android:gravity=“top”,但是在复选框的文本中得到了一些额外的填充。 我试过了,但没有成功 我试过: <CheckBox android:id="@+id/chkConfirmSymbol" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_m

我想将顶部的
复选框
与两行文本对齐。我希望复选框和文本在顶部的同一行中

注意:我尝试了
android:gravity=“top”
,但是在复选框的文本中得到了一些额外的填充。

我试过了,但没有成功

我试过:

<CheckBox
     android:id="@+id/chkConfirmSymbol"
     android:layout_width="0dp"
     android:layout_height="wrap_content"
     android:layout_marginLeft="@dimen/margin_10"
     android:layout_weight="1"
     android:button="@drawable/selector_checkbox_black"
     android:enabled="false"
     android:gravity="top"
     android:paddingTop="0dp"
     android:paddingLeft="@dimen/margin_10"
     android:text="@string/at_least_1_symbol"
     android:textColor="@drawable/selector_checkbox_text_black"
     android:textSize="@dimen/font_11" />

输出:

根据上面的图片,我在文本中得到了一些填充


任何帮助都将不胜感激。谢谢大家!

你不能用简单的方法吗?为什么需要
android:layout\u width=“0dp”
android:layout\u weight=“1”



或者您可以查看它,它应该会对您有所帮助。

您可以在
sdk>platforms>API\u VERSION>data>res>drawable中找到用于复选框的默认可绘制文件

如果您检查与默认可绘制文件一起使用的任何资源图像,例如此可绘制文件中使用的
btn\u check\u off
,您可以看到默认图像本身有一些默认填充。并且您正在使用的自定义图像缺少它。将默认填充添加到图像资源中,应该可以正常工作

请参见下图以供参考。

我刚刚通过给android:paddingTop一些
来管理它,你也可以尝试用同样的方法来做

XML代码(用于布局):

<?xml version="1.0" encoding="utf-8"?>

<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <CheckBox
        android:id="@+id/cb_confirm"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="10dp"
        android:enabled="false"
        android:paddingTop="5dp"
        android:paddingStart="10dp"
        android:paddingEnd="0dp"
        android:text="@string/at_least_1_symbol"
        android:textColor="@android:color/background_dark"
        android:textSize="12sp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toBottomOf="parent" />

</android.support.constraint.ConstraintLayout>


我希望,这对您有所帮助。

基本上就是这样做的:

<CheckBox
    android:layout_width="match_parent"
    android:minLines="2"

您想要的输出是什么?复选框和文本在顶部的同一行中。你可以看到复选框现在太高了:(@Annie你能不能把它添加到你的问题中,因为现在它没有指定“复选框和顶部同一行中的文本”。你正在使用这些行来限制编辑文本的宽度
android:layout\u width=“0dp”android:layout\u weight=“1”
因此,在当前的宽度中,文本的高度将增加,复选框圆圈将位于顶部。@fatemehfallahiarezoudar即使去掉了重量和宽度,它也会显示相同的输出注意:如果用户在辅助功能设置中更改字体大小,这将不起作用。为此,请查看此选项,完全忽略用户的首选项s、 android:textSize=“13dp”。也许尝试使用sp而不是dp构建按钮会有所帮助(不确定您是否尝试过)
<CheckBox
    android:layout_width="match_parent"
    android:minLines="2"