0

Эй Я делаю простой чат-приложение. У меня эти два макеты пройти для инфлятор, чтобы добавить к RecyclerView: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

Вы можете сделать два элемента полной ширины языка XML (match_parent) и перемещать атрибуты layout_gravity и background к ребенку TextView:

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

ха-ха, извините братан, ты был прав , Благодаря! –

Смежные вопросы