我在應用內部製作了一個messenger功能,並希望根據持有者傳遞的值(必須是START或END)來更改佈局引力。一切工作正常,除了重力。它在START開始供所有持有者使用。有沒有解決方法?Android RecyclerView問題中的不同佈局
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
Message message = mMessageList.get(position);
if(message.getSender().equals("System")){
holder.content.setBackgroundResource(R.drawable.message_bubble_out);
holder.content.setTextColor(Color.parseColor("#000000"));
holder.messageLayout.setGravity(Gravity.END);
}
holder.content.setText(message.getContent());
}
消息佈局XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/message_wrapper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="@+id/message_content"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:background="@drawable/message_bubble_out"
android:text="Hi, rangertS!"
android:textColor="#FFFFFF" />
</LinearLayout>
messageLayout定義:
messageLayout = (LinearLayout) view.findViewById(R.id.message_wrapper);
'messageLayout'的類型是什麼? – ridsatrio
messageLayout是一個LinearLayout – NickitaX
你可以更新你的問題還包括持有者和'messageLayout'的定義嗎?因爲從上面給出的片段來看,這個問題似乎在別的地方。 – ridsatrio