I made the layout from xml with on tablet layout of emulator size. But when open on same layout on android phone device then every thing distorted, So can i make a xml layout that will work fine in both of device phone and tablet also. Please suggest me, appreciate your answer.
-
you will have to design your layouts and drawables for both screen sizes. check the docs has all the info you need http://developer.android.com/guide/practices/screens_support.html – Raghunandan Jun 28 '13 at 05:23
-
2I have given a detailed answer about this here: http://stackoverflow.com/a/12742888/1369222 – Anup Cowkur Jun 28 '13 at 05:51
-
See [this](http://stackoverflow.com/questions/14078460/android-how-to-scale-a-layout-with-screen-size/19925666#19925666) answer. – Elhanan Mishraky Feb 11 '15 at 07:37
4 Answers
Make your resource like this.
res/layout/my_layout.xml // layout for normal screen size ("default")
res/layout-small/my_layout.xml // layout for small screen size
res/layout-large/my_layout.xml // layout for large screen size
res/layout-xlarge/my_layout.xml // layout for extra large screen size
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation
res/drawable-mdpi/my_icon.png // bitmap for medium density
res/drawable-hdpi/my_icon.png // bitmap for high density
res/drawable-xhdpi/my_icon.png // bitmap for extra high density
For more reference. reference1.
Add this in your manifest.xml
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens= "true"
android:anyDensity="true"
/>
Hope this will help you.

- 2,340
- 21
- 43
-
image size will be same in all drawable folder? or will be putted the different size of image in each and every layout? – Sunil Kumar Jun 28 '13 at 05:30
-
you should place different size of image. according to density.. because small images only fit for small screen . but it wont fit for larger screen because it looks very small. so we are moving like this. it's better to put different size of image. – Nirmal Jun 28 '13 at 05:32
-
@Nirmal Hi, I'm also used this but does not get solution. My device always shows normal layout only. I have added this permission 'android:configChanges="orientation|keyboardHidden|screenSize|screenLayout" ' This will affect anything. – SathishKumar Jul 05 '13 at 06:22
-
-
Make two separate layout for mobile or tablet just go your default layout design and click on orientation for preview and after click on create tablet variation. And after will see two layout for tab and mobile this is a easiest.

- 1,018
- 1
- 11
- 16
Use Tables and weights to create the same or similar aspect ratio on a phone that would be on a tablet. I would only create different Layouts as a last resort.
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight=".33" >
//Note: You will need some other TableRows fill in the difference of this Table Row..2 more of the same will equal 1.
<TextView
android:id="@+id/x"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginLeft="3dp"
android:layout_weight=".33"
android:background="@drawable/buttonx"
android:gravity="center"
android:text="Words"
android:textColor="#ffffff"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="@+id/x2"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginLeft="3dp"
android:layout_weight=".33"
android:background="@drawable/buttonx2"
android:gravity="center"
android:text="Other Words"
android:textColor="#ffffff"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="@+id/x3"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginLeft="3dp"
android:layout_weight=".33"
android:background="@drawable/buttonx3"
android:gravity="center"
android:text="More Words"
android:textColor="#ffffff"
android:textSize="16sp"
android:textStyle="bold" />
</TableRow>

- 801
- 11
- 33
-
This is making what's inside your layout a percentage of the page. So whether it's on a TV Screen or the smallest device the aspect ratio is still the same. – SmulianJulian Jun 28 '13 at 06:07
You can create two seperate layout for your phone and Tab. What you need to do is create a layout file with "filename" for phone and for tab create a layout file by right clicking project and selecting new>android xml layout file> and then type a "filename", click next and select Size from the right pane and select x-large from drop down list. Your layout file for tab is created separately so customise your layout seperately.

- 112
- 1
- 4
- 13