android - How to make the UI to look the same in landscape mode? -
my linearlayout changes screen orientation. in portrait mode, looks perfect:

but in landscape mode looks this:

how can fix ui same on both modes?
<linearlayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/border" android:orientation="vertical"> <linearlayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"> <imageview android:id="@+id/imgfourth1" android:layout_width="70dp" android:layout_height="50dp" android:layout_marginright="25dp" android:layout_marginleft="25dp" android:paddingtop="2dp" android:src="@drawable/amlet1" /> <imageview android:id="@+id/imgfourth2" android:layout_width="70dp" android:paddingtop="2dp" android:layout_height="50dp" android:layout_marginright="25dp" android:contentdescription="@null" android:src="@drawable/lnch1" /> <imageview android:id="@+id/imgfourth3" android:layout_marginright="25dp" android:paddingleft="20dp" android:layout_width="70dp" android:layout_height="50dp" android:paddingtop="2dp" android:contentdescription="@null" android:src="@drawable/supper" /> </linearlayout> <linearlayout android:layout_width="wrap_content" android:layout_height="20dp" android:background="@drawable/border4" android:orientation="horizontal" > <textview android:id="@+id/txtfth1" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margintop="2dp" android:layout_marginleft="25dp" android:paddingleft="10dp" android:paddingright="10dp" android:gravity="center" android:contentdescription="@null" android:text="breakfast" /> <textview android:id="@+id/txtfth2" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginleft="25dp" android:paddingleft="10dp" android:gravity="center" android:paddingright="35dp" android:layout_margintop="2dp" android:contentdescription="@null" android:text="lunch" /> <textview android:id="@+id/txtfth3" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginleft="20dp" android:layout_margintop="2dp" android:gravity="center" android:paddingright="30dp" android:contentdescription="@null" android:text="supper" /> </linearlayout> </linearlayout>
you can create 2 different layouts, 1 portrait mode , 1 landscape mode. solve problem.
keep 1. portrait mode layout in res/layout folder , 2. landscape mode layout in res/layout-land folder. android take appropriate layout based on orientation.
*edit : single layout* **
if want use single layout portrait , landscape orientation following should you
i have used android:weightsum , android:layout_weight make proper.
<?xml version="1.0" encoding="utf-8"?> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:weightsum="100"> <imageview android:id="@+id/imgfourth1" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="33" android:src="@drawable/ic_launcher" /> <imageview android:id="@+id/imgfourth2" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="33" android:src="@drawable/ic_launcher" /> <imageview android:id="@+id/imgfourth3" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="33" android:src="@drawable/ic_launcher" /> </linearlayout> <linearlayout android:layout_width="match_parent" android:layout_height="20dp" android:orientation="horizontal" android:weightsum="100" > <textview android:id="@+id/txtfth1" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="33" android:gravity="center_horizontal" android:text="breakfast" /> <textview android:id="@+id/txtfth2" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="33" android:gravity="center_horizontal" android:text="lunch" /> <textview android:id="@+id/txtfth3" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="33" android:gravity="center_horizontal" android:text="supper" /> </linearlayout>
Comments
Post a Comment