Android studio 复选框文本未与复选框的中心垂直对齐

Android studio 复选框文本未与复选框的中心垂直对齐,android-studio,android-checkbox,Android Studio,Android Checkbox,我有5个复选框,每个复选框的“文本与复选框中心垂直对齐。我曾尝试在chckbox中添加填充或边框,但没有效果,因为据我所知,您无法在文本中专门添加填充。这张图片可以更好地解释我的问题 复选框文本在第一个复选框上未对齐。我想要的结果是第四个复选框 编辑 我从数组以编程方式创建复选框: LinearLayout typeLinLayout = (LinearLayout)findViewById(R.id.typeLinLay); TableRow.LayoutParams ch

我有
5个复选框
,每个复选框的“
文本
与复选框中心垂直对齐。我曾尝试在chckbox中添加填充或边框,但没有效果,因为据我所知,您无法在文本中专门添加填充。这张图片可以更好地解释我的问题

复选框文本在第一个复选框上未对齐。我想要的结果是第四个复选框

编辑

我从数组以编程方式创建复选框:

    LinearLayout typeLinLayout = (LinearLayout)findViewById(R.id.typeLinLay);

    TableRow.LayoutParams checkParams = new TableRow.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
    checkParams.setMargins(0, 15, 0, 0);

    for (int k = 0; k < config.checkBoxTypeFindViewById.length; k++)
    {
        CheckBox checkBox = new CheckBox(this);
        checkBox.setLayoutParams(checkParams);
        typeLinLayout.addView(checkBox, checkParams);

        checkBox.setId(config.checkBoxTypeFindViewById[k]);
        checkBox.setText(config.checkBoxTextType[k]);
        checkBox.setOnClickListener(onCheckboxClickedType);
        checkBox.setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
        checkBox.setGravity(Gravity.LEFT);
        checkBox.setTextDirection(View.TEXT_DIRECTION_ANY_RTL);
        checkBox.setTextSize(16);
        checkBox.setAllCaps(true);
    }
LinearLayout typeLinLayout=(LinearLayout)findViewById(R.id.typeLinLay);
TableRow.LayoutParams checkParams=新建TableRow.LayoutParams(LayoutParams.FILL\u父级,LayoutParams.WRAP\u内容);
checkParams.setMargins(0,15,0,0);
对于(int k=0;k
以下是xml:

<?xml version="1.0" encoding="utf-8"?>
<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">

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:background="@color/mainTextBGColor">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_marginStart="15dp"
        android:layout_marginEnd="15dp">

        <TextView
            android:id="@+id/typesText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="30dp"
            android:layout_marginBottom="10dp"
            android:textSize="@dimen/optionsHeaders"
            android:fontFamily="@font/lato"
            android:textColor="@color/mainBGColor"
            android:text="@string/optionsType"/>

        <LinearLayout
            android:id="@+id/typeLinLay"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:backgroundTint="@color/mainBGColor">
        </LinearLayout>
    </LinearLayout>
</ScrollView>
</RelativeLayout>


非常感谢您的帮助

你能把你的xml代码放在这里吗?请看我的编辑。