Android重力左与右剪辑差

Android重力左与右剪辑差,android,layout,Android,Layout,我发现左对齐和右对齐的文本视图在剪辑方面存在差异,我不理解这一点 下面是一个布局示例: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical"

我发现左对齐和右对齐的文本视图在剪辑方面存在差异,我不理解这一点

下面是一个布局示例:

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

    <RelativeLayout
        android:id="@+id/fullLay"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="left">

        <RelativeLayout
            android:id="@+id/layout_message_content_container"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="15dp"
            android:background="@color/blue">

            <TextView android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="Hello World"/>
        </RelativeLayout>

        <TextView
            android:id="@+id/timestamp_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/layout_message_content_container"
            android:maxLines="1"
            android:layout_alignLeft="@+id/layout_message_content_container"
            android:text="This is a long sample label string"/>
    </RelativeLayout>

</LinearLayout>

这给了我期望的布局:

标题标签位于“Hello World”下方。但是,如果我更改此选项,使android:gravity=“right”并使用layout\u alignRight而不是layout\u alignLeft,标题视图将被剪裁

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

    <RelativeLayout
        android:id="@+id/fullLay"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="right">

        <RelativeLayout
            android:id="@+id/layout_message_content_container"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="15dp"
            android:background="@color/blue">

            <TextView android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="Hello World"/>
        </RelativeLayout>

        <TextView
            android:id="@+id/timestamp_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/layout_message_content_container"
            android:maxLines="1"
            android:layout_alignRight="@+id/layout_message_content_container"
            android:text="This is a long sample label string"/>
    </RelativeLayout>

</LinearLayout>

现在,标题视图被剪裁为其上方视图的宽度

如何使此视图与上面的视图对齐但不剪裁?

试试这个-

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

    <RelativeLayout
        android:id="@+id/layout_message_content_container"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end"
        android:background="@color/blue"
        android:padding="15dp">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello World" />
    </RelativeLayout>

    <TextView
        android:id="@+id/timestamp_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end"
        android:maxLines="1"
        android:text="This is a long sample label string" />

</LinearLayout>

酷-开始和结束与左和右的区别。仍然不明白为什么原来的方法不起作用,但谢谢!哦,是的。始终使用
start
end
来支持RTL布局。实际上,我尝试了
start
end
,但奇怪的是,它在现有代码中不起作用。
<?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">

    <TextView
        android:id="@+id/hello_world"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@color/blue"
        android:padding="15dp"
        android:text="Hello World"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/timestamp_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:maxLines="1"
        android:text="This is a long sample label string"
        android:textAlignment="textEnd"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@id/hello_world" />

</android.support.constraint.ConstraintLayout>