I have created the below layout using Linear Layout , its running fine but i have one doubt that it can be optimized because i have created this UI using nested Linear Layout , i think its not well.
So Can you please help me to optimize this Linear Layout either by using Relative Layout or else ?
I have defined a layout like:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="6dip">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="fill_parent"
android:layout_marginLeft="10dip">
<TextView
android:id="@+id/txtViewTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical"
android:textSize="18dip"
android:text="hello"
/>
<TextView
android:id="@+id/txtViewDescription"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical"
android:textSize="14dip"
android:text="hello"
/>
</LinearLayout>
<ImageView
android:id="@+id/image"
android:layout_width="50dip"
android:layout_height="fill_parent"
android:src="@drawable/arrow"
android:layout_marginLeft="3dip"
android:scaleType="center"/>
</LinearLayout>
Here is a refactoring of your code using RelativeLayout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:padding="6dip">
<ImageView android:layout_marginLeft="3dip" android:id="@+id/image"
android:src="@drawable/arrow_cell"
android:layout_width="50dip" android:scaleType="center"
android:layout_alignParentRight="true" android:layout_height="wrap_content" android:layout_centerVertical="true"></ImageView>
<TextView android:textSize="18dip" android:layout_height="wrap_content"
android:layout_width="fill_parent" android:id="@+id/txtViewTitle"
android:layout_marginLeft="10dip" android:text="hello"
android:gravity="center_vertical" android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/image"></TextView>
<TextView android:textSize="14dip" android:layout_height="wrap_content"
android:layout_width="fill_parent" android:id="@+id/txtViewDescription"
android:layout_marginLeft="10dip" android:text="hello2"
android:gravity="center_vertical" android:layout_below="@+id/txtViewTitle"
android:layout_toLeftOf="@+id/image"></TextView>
</RelativeLayout>
As you said you want to use it as a row in a ListView, I changed the hight of the parent layout to "wrap_content".