0

我有一个这样的 xml 标记:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:orientation="vertical">

    <GridLayout
            android:layout_width="match_parent"
            android:layout_height="fill_parent">
        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="13:40"
                android:id="@+id/textView" android:layout_marginLeft="10dp"/>
        <LinearLayout
                android:orientation="vertical"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp">
            <TextView
                    android:id="@+id/nameText"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:text="Large Text"
                    android:textAppearance="?android:attr/textAppearanceLarge" android:layout_row="0"
                    android:layout_column="0"/>
            <TextView
                    android:id="@+id/originalText"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:text="Medium Text"
                    android:textAppearance="?android:attr/textAppearanceMedium" android:layout_row="1"
                    />
        </LinearLayout>
        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="right"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="150-220"
                android:id="@+id/textView2" android:layout_marginRight="10dp"/>
    </GridLayout>

</LinearLayout>

在 IDE 中看起来不错:

在此处输入图像描述

但是当在模拟器右翼中运行应用程序时,右翼textView2未与右侧对齐,尽管我在标记中有它:

在此处输入图像描述

我做错了什么?

谢谢。

4

1 回答 1

0

Try this way,hope this will help you to solve your problem.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

    <GridLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:columnCount="4">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="13:40"
            android:layout_marginLeft="10dp"
            android:layout_column="0"
            android:layout_row="0"/>
        <LinearLayout
            android:orientation="vertical"
            android:layout_marginLeft="10dp"
            android:layout_column="1"
            android:layout_columnSpan="2"
            android:layout_row="0">
            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:text="Large Text"
                android:textAppearance="?android:attr/textAppearanceLarge"/>
            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:text="Medium Text"
                android:textAppearance="?android:attr/textAppearanceMedium"/>
        </LinearLayout>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="150-220"
            android:layout_marginRight="10dp"
            android:layout_row="0"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="13:40"
            android:id="@+id/textView"
            android:layout_marginLeft="10dp"
            android:layout_column="0"
            android:layout_row="1"/>
        <LinearLayout
            android:orientation="vertical"
            android:layout_marginLeft="10dp"
            android:layout_column="1"
            android:layout_columnSpan="2"
            android:layout_row="1">
            <TextView
                android:id="@+id/nameText"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:text="Large Text"
                android:textAppearance="?android:attr/textAppearanceLarge"/>
            <TextView
                android:id="@+id/originalText"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:text="Medium Text"
                android:textAppearance="?android:attr/textAppearanceMedium"/>
        </LinearLayout>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="150-220"
            android:id="@+id/textView2"
            android:layout_marginRight="10dp"
            android:layout_row="1"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="13:40"
            android:layout_marginLeft="10dp"
            android:layout_column="0"
            android:layout_row="2"/>
        <LinearLayout
            android:orientation="vertical"
            android:layout_marginLeft="10dp"
            android:layout_column="1"
            android:layout_columnSpan="2"
            android:layout_row="2">
            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:text="Large Text"
                android:textAppearance="?android:attr/textAppearanceLarge"/>
            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:text="Medium Text"
                android:textAppearance="?android:attr/textAppearanceMedium"/>
        </LinearLayout>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="150-220"
            android:layout_marginRight="10dp"
            android:layout_row="2"/>
    </GridLayout>

</LinearLayout>
于 2014-09-02T11:38:38.373 回答