0

I tried a lot for handling multiple Tablet and handset screens on Android but could not get right way of doing this. In some cases I am getting errors and some does not work. I also posted Stack Question but did not receive satisfied result. I want to show a list and discription side by side on tablet screen whereas only list in mobile screen. Is there any good and easy way of doing this? I also tried to this but could not get the goal.

Community
  • 1
  • 1
user6750923
  • 429
  • 1
  • 9
  • 22

2 Answers2

0

yes you can do this. There is a way where you can select layout based on the device.

res/layout/my_layout.xml              // layout for normal screen size ("default")
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/graphic.png         // bitmap for medium-density
res/drawable-hdpi/graphic.png         // bitmap for high-density
res/drawable-xhdpi/graphic.png        // bitmap for extra-high-density
res/drawable-xxhdpi/graphic.png       // bitmap for extra-extra-high-density

res/mipmap-mdpi/my_icon.png         // launcher icon for medium-density
res/mipmap-hdpi/my_icon.png         // launcher icon for high-density
res/mipmap-xhdpi/my_icon.png        // launcher icon for extra-high-density
res/mipmap-xxhdpi/my_icon.png       // launcher icon for extra-extra-high-density
res/mipmap-xxxhdpi/my_icon.png      // launcher icon for extra-extra-extra-high-density

in case of 10' tab create a layout in

res/layout-sw720dp/my_layout.xml

in case of 7' tab create a layout in

res/layout-sw600dp/my_layout.xml


 <?xml version="1.0" encoding="utf-8"?>

<TextView
    android:id="@+id/title_detailfragment"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/detail_fragment"/>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">
    <fragment
        android:name="com.example.fyp_awais.tab.MainActivity$MyListFragment"
        android:id="@+id/list_fragment"
        android:layout_height="match_parent"
        android:layout_width="0dp"
        android:layout_weight="1" />
    <fragment
        android:name="com.example.fyp_awais.tab.MainActivity$MyDetailFragment"
        android:id="@+id/detail_fragment"
        android:layout_height="match_parent"
        android:layout_width="0dp"
        android:layout_weight="1" />

</LinearLayout>

Rushi Ayyappa
  • 2,719
  • 2
  • 14
  • 30
  • Yes I know this. But how to show both fragments in tablet layout side by side? I already mentioned this in the question. You can also take a glance at my question `http://stackoverflow.com/questions/41330315/binary-xml-file-line-20-error-inflating-class-fragment-android` – user6750923 Dec 27 '16 at 05:16
  • take a LinearLayout and then take two RelativeLayouts and assign weights to them for width. – Rushi Ayyappa Dec 27 '16 at 05:17
  • now use this RelativeLayouts to show your fragments – Rushi Ayyappa Dec 27 '16 at 05:17
  • If you refer me to working example. I shall be great thankful to you. – user6750923 Dec 27 '16 at 05:33
0

Use the xhdpi resources and try to set all the layouts at the runtime using the layout params according to the device.

or let the android decide what is best for the device create following folders

layout-large
layout-small
layout-sw600
layout-sw720

and similar folders to organize your layouts better

Anchal Singh
  • 319
  • 3
  • 12