0

ちょっと私は簡単なチャットアプリケーションを作っています。私はRecyclerViewに追加するインフレータのために合格するには、これらの2つのレイアウトを持っている:LinearLayout RecyclerView

received_msg.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="#f00"> 

<TextView 
    android:text="Hello" 
    android:textColor="#fff" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 

</LinearLayout> 

sent_msg.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="#fff" 
    android:layout_gravity="right"> 

<TextView 
    android:text="Text" 
    android:textColor="#f00" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 

</LinearLayout> 

RecyclerView:

<android.support.v7.widget.RecyclerView 
    android:padding="10dp" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:scrollbarStyle="outsideOverlay" 
    android:scrollbars="vertical" /> 

layout_gravityプロパティは、sent_msg.xmlのLinearLayoutには何の効果もないようです。何をすべきか?

答えて

0

次の2つの項目XMLの全幅(match_parent)を作成し、子のTextViewにlayout_gravitybackground属性を移動することができます。

sent_msg.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent"     (* Changed) 
    android:layout_height="wrap_content"> 

<TextView 
    android:text="Text" 
    android:background="#fff"       (* Changed) 
    android:textColor="#f00" 
    android:layout_gravity="right"      (* Changed) 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 

</LinearLayout> 
+0

ハハ、申し訳ありませんあなたは正しかった仲間。ありがとう! –