Java 在列表视图中将文本视图向右移动

Java 在列表视图中将文本视图向右移动,java,android,Java,Android,正如您在我提供的图像中所看到的,我的“列标题”和“列内容”不一致。列内容正在向左移动。我如何纠正它? 我的整个xml代码都在ScrollView中。它在早期工作,即专栏和内容排成一行,但现在内容正在向左移动,即使我没有做任何比以前新的事情 我的xml代码: <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"

正如您在我提供的图像中所看到的,我的“列标题”和“列内容”不一致。列内容正在向左移动。我如何纠正它? 我的整个xml代码都在ScrollView中。它在早期工作,即专栏和内容排成一行,但现在内容正在向左移动,即使我没有做任何比以前新的事情

我的xml代码:

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="@drawable/gradient_background"
    android:scrollbars="vertical">

    <HorizontalScrollView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <TableLayout

            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:stretchColumns="0,1,2,3,4"
            android:background="@drawable/gradient_background">

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1">

                <TextView
                    android:layout_width="253dp"
                    android:layout_height="match_parent"
                    android:layout_column="0"
                    android:layout_margin="1dp"
                    android:gravity="center"
                    android:text="Banana(1/2 medium)"
                    android:textAppearance="?android:attr/textAppearanceLarge" />

                <TextView
                    android:id="@+id/tv_table_layout_row1_cal"
                    android:layout_width="192dp"
                    android:layout_height="match_parent"
                    android:layout_column="1"
                    android:layout_margin="1dp"
                    android:gravity="center"
                    android:text="55"
                    android:textAppearance="?android:attr/textAppearanceLarge" />

                <EditText
                    android:id="@+id/et_table_layout_row1_con"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:textAppearance="?android:attr/textAppearanceLarge"
                    android:hint=" Quantity or 0"
                    android:layo-ut_margin="1dp"
                    android:layout_column="2"
                    android:gravity="center"
                    android:inputType="number"
                    android:background="@drawable/tv_round_corners_with_white_background"/>

                <TextView
                    android:id="@+id/tv_table_layout_row1_tot"
                    android:layout_width="120dp"
                    android:layout_height="match_parent"
                    android:layout_column="3"
                    android:layout_margin="1dp"
                    android:gravity="center"
                    android:hint="Total"
                    android:textAppearance="?android:attr/textAppearanceLarge"/>

            </TableRow>

        </TableLayout>

    </HorizontalScrollView>

</ScrollView>

取决于
TextView
所在的父级。在XML中有几个选项:

  • LinearLayout
    FrameLayout
    -
    android:layout\u gravity=“right”
    (或
    “end”
    如果minSdk>16)
  • RelativeLayout
    -
    android:layout\u alignParentRight=“true”
  • ConstraintLayout
    MotionLayout
    -
    app:layout\u constraintEnd\u toEndOf=“parent”

这会将实际视图向右移动。如果要移动文本,请在
TextView
本身上设置
android:gravity=“right”
(如果minSdk>16,则设置
“end”

您能参考我编辑的问题并帮助我吗?