Я пытаюсь установить гравитацию для детей в RecyclerView, но похоже, что LayoutParams не имеет метода гравитации. Я попытался следующие:Можно ли программно установить гравитацию для детей RecyclerView в Android?
RecyclerView.LayoutParams params = new RecyclerView.LayoutParams(
RecyclerView.LayoutParams.WRAP_CONTENT, RecyclerView.LayoutParams.WRAP_CONTENT);
Я также попытался следующие:
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
В обоих случаях params.setMargin(int, int, int, int)
работает просто отлично, а маржа устанавливается правильно.
Мой 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"/>
Мой RelativeLayout (ребенок 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>
То, что я хочу быть в состоянии сделать это params.setGravity(int)
или любой другой хак, что делает это возможным. Благодарю.
ли ответ здесь помочь? http://stackoverflow.com/questions/29426101/set-gravity-programmatically-for-item-in-recycerview-android – user4989692
@ user4989692 Нет, к сожалению, это не так! – Loolooii