我有一个回收站视图,这个回收站视图会膨胀一些消息。我试图以编程方式更改对齐这些消息,但它无法正常工作。我的布局如下:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:id="@+id/card_view_relative"
android:layout_marginRight="7dp"
android:layout_marginLeft="50dp">
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/tools"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_alignParentEnd="true"
android:layout_height="match_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/row_background">
<TextView
android:id="@+id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="5dp"
android:textSize="13dp"
android:textColor="@color/colorAccent" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
我的代码如下所示:
RelativeLayout cardViewRelative = (RelativeLayout)v.findViewById(R.id.card_view_relative);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.MATCH_PARENT);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
messagesViewHolder.cardViewRelative.setLayoutParams(layoutParams);
我不知道这里有什么问题。