Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/200.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 对齐我的TableRow中的项目_Android_Xml_Alignment_Tablerow - Fatal编程技术网

Android 对齐我的TableRow中的项目

Android 对齐我的TableRow中的项目,android,xml,alignment,tablerow,Android,Xml,Alignment,Tablerow,我有一个TableRow,它有四个文本视图。我正在尝试对齐TableRow中的项目。当项目1(TextView)的字符串很长时,它会推送项目2。我试着将android:layout\u weight=“1”设置为相同的值,但没有成功。有什么方法可以对齐项目吗 这是my row.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/

我有一个TableRow,它有四个文本视图。我正在尝试对齐TableRow中的项目。当项目1(TextView)的字符串很长时,它会推送项目2。我试着将android:layout\u weight=“1”设置为相同的值,但没有成功。有什么方法可以对齐项目吗

这是my row.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:background="@color/white_background"
    android:orientation="vertical" >


    <TableRow
        android:id="@+id/product_header"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white_background"
        android:layout_margin="5dp"
        android:orientation="vertical" >

        <View
            android:layout_width="0dp"
            android:layout_height="1dp"
            android:background="@color/black" />

        <TextView
            android:id="@+id/product_name"
            style="@style/product_row"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="8"
            android:ellipsize="end"
            android:singleLine="true"
            android:layout_marginLeft="1dp"
            android:textColor="@color/black" />

        <TextView
            android:id="@+id/product_id"
            style="@style/product_row"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="100dp"
            android:layout_weight="5"
            android:ellipsize="end"
            android:singleLine="true"
            android:gravity="right"
            android:textColor="@color/black" />
        <View
            android:layout_width="0dp"
            android:layout_height="1dp"
            android:background="@color/black" />
        <TextView
            android:id="@+id/total_quantity"
            style="@style/product_row"
            android:layout_width="wrap_content"
            android:layout_weight="3"
            android:ellipsize="end"
            android:singleLine="true"
            android:layout_marginRight="40dp"
            android:gravity="center_horizontal"
            android:layout_height="wrap_content"
            android:textColor="@color/black" />
        <View
            android:layout_width="0dp"
            android:layout_height="1dp"
            android:background="@color/black" />
        <TextView
            android:id="@+id/total_value_amt"
            style="@style/product_row"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_marginLeft="5dp"
            android:layout_weight="1"
            android:ellipsize="end"
            android:singleLine="true"
            android:gravity="right"
            android:text="@string/product_row_value"
            android:textColor="@color/black"/>
    </TableRow>

    <TextView
        android:id="@+id/employee_header"
        style="@style/product_row"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/product_header"
        android:layout_gravity="left"
        android:layout_marginLeft="5dp"
        android:gravity="left"
        android:visibility="gone"
        android:text="@string/crew" />
    <TextView
        android:id="@+id/quantity_header"
        style="@style/product_row"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/product_header"
        android:layout_gravity="right"
        android:layout_marginRight="5dp"
        android:gravity="right"
        android:visibility="gone"
        android:text="@string/quantity_sold" />
    <TableLayout
        android:id="@+id/sales_report_table"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/grey_light"
        />
    <TextView
        style="@style/product_row"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_gravity="center"
        android:layout_marginRight="5dp"
        android:gravity="right"
        android:textColor="@color/black_font" />

</RelativeLayout>

试试这个:这可能会对你有所帮助

这是我的示例代码

 <TableRow
            android:id="@+id/product_header"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/white"
            android:orientation="vertical"
            android:weightSum="4">

            <TextView
                android:id="@+id/product_name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:singleLine="true"/>

            <TextView
                android:id="@+id/product_id"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:singleLine="true"/>

            <TextView
                android:id="@+id/total_quantity"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:singleLine="true"/>

            <TextView
                android:id="@+id/total_value_amt"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:singleLine="true" />
        </TableRow>

我将TableRow放入TableLayout中,并使用以下命令对齐TableRow

android:shrinkColumns="0"
android:stretchColumns="*" // Inside TableLayout.
我还添加了一个

android:weightSum="10" 

并使用android:layout\u-weight属性平均划分我的表行。这使我的textView具有相等的边距。使用android:layout\u weight帮助我平均划分了各个列。

有什么评论/帮助吗?