我正在尝试在我的应用程序中创建类似聊天的功能,并且对于我正在使用卡片视图的聊天文本。我希望卡片视图与已发送消息的屏幕右侧对齐。但是,当我将重力属性设置为 cardview 的父级时,它适用于所有其他属性,但 cardview 不会让步。请告诉我如何将 layout_gravity 设置为 cardview(将采用动态方法)。谢谢。
这是我的 model_msg.xml 文件,发送的 msgs 的设置在适配器类中完成:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_marginEnd="40dp"
android:layout_marginTop="6dp"
android:layout_marginBottom="6dp"
android:layout_height="wrap_content"
android:id="@+id/rl_msg"
android:layout_gravity="center">
<TextView
android:paddingStart="8dp"
android:text="Sender Name"
android:maxLines="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tv_senderName"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true" />
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
card_view:cardBackgroundColor="@color/cBgrMsg"
card_view:cardElevation="6dp"
android:layout_height="wrap_content"
android:id="@+id/card_msgText"
android:layout_below="@id/tv_senderName"
card_view:cardCornerRadius="6dp">
<TextView
android:text="The message will come here which is gonna be a lot larger than this textView can handle and at that time to avoid any bugs or not to discard and functionalities I would have to utilize my mind a lot which is gonna be so tiresome and annoying that I would think about leaving this app in middle without finishing it. Damn."
android:padding="6dp"
android:textSize="16sp"
android:maxLength="500"
android:layout_width="wrap_content"
android:textColor="@color/cWhite"
android:layout_height="wrap_content"
android:id="@+id/tv_msg"
android:layout_below="@id/tv_senderName" />
</android.support.v7.widget.CardView>
<TextView
android:text="Nothing to show."
android:padding="4dp"
android:background="#0000"
android:textSize="10sp"
android:textStyle="italic"
android:layout_width="wrap_content"
android:gravity="start"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:textColor="#999999"
android:layout_height="wrap_content"
android:id="@+id/tv_sentAt"
android:layout_below="@id/card_msgText" />
</RelativeLayout>