A
A
akass2015-05-22 00:23:23
Android
akass, 2015-05-22 00:23:23

How to correctly display messages in such a layout?

There is such a layout. How to display messages in it?a8b54282d36c45708a8b1bc51911c80b.JPG

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:paddingRight="20dip"
    android:layout_height="wrap_content">
    <LinearLayout
        android:id="@+id/wrapper"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:gravity="left"
        android:background="@drawable/bubble_yellow">
        <RelativeLayout
            android:id="@+id/nicknameAndTimeWrapper"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">
            <TextView
                android:id="@+id/nick"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="left"
                android:textStyle="bold"
                android:text="Shyro:"
                android:layout_margin="1dip"
                android:paddingLeft="1dip"
                android:textColor="@android:color/primary_text_light" />
        </RelativeLayout>
        <TextView
            android:id="@+id/message"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="left"
            android:layout_margin="1dip"
            android:paddingLeft="1dip"
            android:text="Hello bubbles"
            android:textColor="@android:color/primary_text_light" />
    </LinearLayout>
</LinearLayout>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
swba, 2015-05-22
@akass

Layout-wise, the outer LinearLayout and inner RelativeLayout look redundant. What is the meaning of their existence?
As to your question, it's not clear to me. Search for the desired TextView by parent with findViewById, then set the text with setText :

parent.findViewById(R.id.message).setText("new message");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question