Android listview apperence as a listview chat app app

Hi everyone, I need to develop a layout like an app for chatting apps, for example this in this I want to display the time after the text view of the chat is finished.

For this I did

<RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/blue" >

                <TextView
                    android:id="@+id/tv_message_chat_item_f"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="2dp"
                    android:layout_marginTop="2dp"
                    android:gravity="left|center"

                    android:paddingBottom="@dimen/one_dp"
                    android:paddingLeft="@dimen/fifteen_dp"
                    android:paddingRight="@dimen/five_dp"
                    android:paddingTop="@dimen/one_dp"
                      android:textAppearance="?android:attr/textAppearanceMedium"
                    android:text="fgfdgdf rete tretretret rtrtrwtw fgdfr grtwerwerewr ewrwerew" />

                <TextView
                    android:id="@+id/tv_message_time_f"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:layout_below="@+id/tv_message_chat_item_f"
                    android:layout_marginBottom="2dp"
                   android:paddingRight="@dimen/five_dp"
                    android:gravity="right"
                    android:paddingBottom="@dimen/one_dp"
                    android:text="fgfdg"
                    android:textAppearance="?android:attr/textAppearanceSmall" />



            </RelativeLayout>

      

But doesn't work with large message (texview time not set properly)

+3


source to share


3 answers


<LinearLayout
        android:orientation="horizontal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:gravity="bottom"
        android:background="@drawable/blue"
        android:layout_alignParentStart="true" android:weightSum="10">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="Hi"
            android:layout_weight="1"
            android:id="@+id/textView"
            android:gravity="bottom"
            android:layout_centerVertical="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true" />

        <TextView
            android:id="@+id/textView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="bottom"
            android:layout_marginStart="10dp"
            android:text="Small Text"
            android:textAppearance="?android:attr/textAppearanceSmall" />

    </LinearLayout>

      



+1


source


Assuming yours textView3

is the one with the "Big Message", you should first take advantage of the relative layout capabilities and use android:layout_below="@id/textview2"

, this will prevent textView2 from being matched rather than bottom-up aligning everything.

  <TextView
                android:id="@+id/textView3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/textView2"
                android:layout_centerHorizontal="true"
                android:text="Small Text"
                android:textAppearance="?android:attr/textAppearanceSmall" />

      

then after you set TextView

which will hold your time, you can someday use something like



   <TextView
                    android:id="@+id/textView3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@id/textView2"
                    android:gravity="right"
                    android:layout_alignParentRight="true"
                    android:text="12:00 pm"
                    android:textAppearance="?android:attr/textAppearanceSmall" />

      

Gravity

on the right will allow you to place the text from right to left, since the display time usually does not take more than 6 or 7 characters, this will help.

Hope it solves your problem.

0


source


You will need to implement ImageViews using 9packages (here: link ) AND a listview that can handle CustomLayouts for ListItems (using 9Patch ImageViews).

I think you can implement a list view, so I won't go deeper. Congratulated.

0


source







All Articles