Skip to content Skip to sidebar Skip to footer

Android Layout Confusing

Here is my capture picture: And here is my code: Copy

To work for small texts also (To resize the width of messageIn according to message) and time to appear right of message (not right aligned)

<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/wrapper"android:layout_width="wrap_content"android:layout_height="wrap_content"android:weightSum="1.0" ><LinearLayoutandroid:id="@+id/lin_lay1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1.0" ><TextViewandroid:id="@+id/messageIn"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:layout_margin="5dip"android:background="@drawable/bubble_yellow"android:paddingLeft="10dip"android:text="HIHIHI" /></LinearLayout><LinearLayoutandroid:id="@+id/lin_lay2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="0.1" ><TextViewandroid:id="@+id/timeIn"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:layout_marginTop="15dip"android:padding="5dp"android:text="23:23" /></LinearLayout></LinearLayout>

Solution 2:

Use android:maxwidth in your textview.

Solution 3:

A solution is to set the android:maxWidth="" property of your "messageIn" TextView. On runtime - get the width of the device screen, the width of the "timeIn" TextView and set the difference (screen width - timeIn width) with setMaxWidth(int maxpixels) method of TextView.

See how to get screen size here

See how to get GUI object size here

Solution 4:

You can do it in two ways:-

  1. You can use Linear Layout and set its android:orientation="horizontal" and you need to fix the layout_width for a Textview.

  2. Concatinate time with TextView in the code.

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/wrapper"android:layout_width="fill_parent"android:layout_height="wrap_content"android:orientation="horizontal">
     <TextView
     android:id="@+id/messageIn"
     android:layout_width="200dp"
     android:layout_height="wrap_content"      
     android:text="HIHIHIHIdsfffffffffffffffffffffffffffffffffffffffffffffHIHI" />
    <TextView
     android:id="@+id/timeIn"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"  
     android:layout_marginTop="5dp"
     android:text="23:23"/>
    
    
     </LinearLayout>
    

Solution 5:

make use of layout_weight it will take only assigned space and will not cover time textview.

<LinearLayoutandroid:id="@+id/wrapper"android:layout_width="fill_parent"android:layout_height="wrap_content"android:orientation="horizontal"android:weightsum="1"><TextViewandroid:id="@+id/timeIn"android:layout_width="0dip"android:layout_height="wrap_content"android:layout_weight="0.7"android:layout_gravity="center"android:layout_marginTop="15dip"android:text="23:23"/><TextViewandroid:id="@+id/messageIn"android:layout_width="0dip"android:layout_height="wrap_content"android:layout_weight="0.3"android:layout_margin="5dip"android:background="@drawable/bubble_yellow"android:paddingLeft="10dip"android:text="HIHIHIHIHIHI" /></LinearLayout>

Post a Comment for "Android Layout Confusing"