Search code examples
androidandroid-layoutandroid-fragmentsandroid-framework

How do I setup my fragments such that the layout I am using for phone also works well with tablets?


I am using my app currently ,made of fragments , just on phone. I am planning to add tablet version of the same , but seems like some fragments don't work exactly as expected on the tablet and often many mess up on landscape.So I just needed some pointers how to go about the same? Here is my code for one of the fragments layout in xml :

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/altercolor2" >

    <HorizontalPageView
        android:id="@+id/headline_gallery"
        android:layout_width="match_parent"
        android:layout_height="140dp" />

    <include layout="@layout/loading_no_results" />

</FrameLayout>

How do I alter it such that the height even works on tablet as expected without cutting off some data? Also, should i add another duplicate layout somewhere for this or there's way around it? Any help appreciated,thanks!


Solution

  • Try this. Make a new layout-xlarge folder in /res directory and place all your tablet related xml files in that folder. Android system automatically fetches layout files from this layout-xlarge folder for 7-10 inch screens. And to support landscape mode, design your layout files specifically for landscape mode and put it in layout-land folder. But make sure that the name of the files in all the folders are same.