I'm trying to set gravity for children in RecyclerView, but it looks like the LayoutParams does not have a gravity method. I have tried the following:
RecyclerView.LayoutParams params = new RecyclerView.LayoutParams(
RecyclerView.LayoutParams.WRAP_CONTENT, RecyclerView.LayoutParams.WRAP_CONTENT);
I have also tried the following:
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
In both cases params.setMargin(int, int, int, int)
works just fine and the margin is set correctly.
My RecyclerView:
<android.support.v7.widget.RecyclerView
android:id="@+id/messages_list_view"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/toolbar"
android:layout_marginTop="20dp"/>
My RelativeLayout (child of RecyclerView):
<RelativeLayout
android:id="@+id/message_text_wrapper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:background="@drawable/chat_bubble"
android:layout_margin="16dp"
android:padding="10dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="@+id/message_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:textColor="@android:color/primary_text_light"
android:textSize="18sp"
/>
</RelativeLayout>
What I want to be able to do is params.setGravity(int)
or any other hack that makes this possible. Thanks.