Search code examples
androiduser-interfacescreens

how to set UI on 5.4'',7'' and 10.1'' screens in android?


I am trying to set user interface in android on extra large screens that is 5.4'',7'' and 10.1''. I am unable to set the user interface on the following Screens. Because i am setting its interface in layout-xhdpi but it is picking the layout-mdpi. Please guide me how can i fix this problem.

this one is layout-mdpi code

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg"
android:orientation="vertical"
tools:context=".MainActivity" >

<RelativeLayout
    android:id="@+id/appheader"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_marginTop="45dp" >

    <TextView
        android:id="@+id/textviewquestionnumber"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="35dp"
        android:background="@drawable/no_circle"
        android:gravity="center"
        android:text="0"
        android:textSize="20sp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/textviewscore"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:background="@drawable/score_border"
        android:gravity="center"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:text="Score: 0"
        android:textSize="15dp"
        android:textStyle="bold" />

    <ImageButton
        android:id="@+id/imagebtnhint"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_marginRight="35dp"
        android:background="@drawable/hintbuttonselector"
        android:gravity="center" />
   </RelativeLayout>

   <ImageView
    android:id="@+id/imageviewQuestionImage"
    android:layout_width="190dp"
    android:layout_height="150dp"
    android:layout_below="@+id/appheader"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="10dp"
    android:background="@drawable/pic_box" />

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/imageviewQuestionImage"
    android:paddingLeft="30dp"
    android:paddingRight="30dp"
    android:paddingBottom="30dp"
    android:layout_marginTop="5dp" >

    <Button
        android:id="@+id/option1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/optionsselector"
        android:textColor="@drawable/textcolorselector" />

    <Button
        android:id="@+id/option2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/option1"
        android:layout_marginTop="15dp"
        android:background="@drawable/optionsselector"
        android:textColor="@drawable/textcolorselector" />

    <Button
        android:id="@+id/option3"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/option2"
        android:layout_marginTop="15dp"
        android:background="@drawable/optionsselector"
        android:textColor="@drawable/textcolorselector" />

    <Button
        android:id="@+id/option4"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/option3"
        android:layout_marginTop="15dp"
        android:background="@drawable/optionsselector"
        android:textColor="@drawable/textcolorselector" />
</RelativeLayout>

<FrameLayout
    android:id="@+id/googleads"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true" >

    <com.google.ads.AdView
        xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
        android:id="@+id/adView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId=""
        ads:loadAdOnCreate="true" />
</FrameLayout>

</RelativeLayout>

this code is for layout-xhdpi

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg"
android:orientation="vertical"
tools:context=".MainActivity" >

<RelativeLayout
    android:id="@+id/appheader"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_marginTop="50dp" >

    <TextView
        android:id="@+id/textviewquestionnumber"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="35dp"
        android:background="@drawable/no_circle"
        android:gravity="center"
        android:text="0"
        android:textSize="20sp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/textviewscore"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:background="@drawable/score_border"
        android:gravity="center"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:text="Score: 0"
        android:textSize="15dp"
        android:textStyle="bold" />

    <ImageButton
        android:id="@+id/imagebtnhint"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_marginRight="40dp"
        android:background="@drawable/hintbuttonselector"
        android:gravity="center" />
    </RelativeLayout>

<ImageView
    android:id="@+id/imageviewQuestionImage"
    android:layout_width="190dp"
    android:layout_height="150dp"
    android:layout_below="@+id/appheader"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="30dp"
    android:background="@drawable/pic_box" />

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/imageviewQuestionImage"
    android:layout_marginTop="20dp"
    android:paddingBottom="30dp"
    android:paddingLeft="30dp"
    android:paddingRight="30dp" >

    <Button
        android:id="@+id/option1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="30dp"
        android:background="@drawable/optionsselector"
        android:textColor="@drawable/textcolorselector" />

    <Button
        android:id="@+id/option2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/option1"
        android:layout_marginTop="30dp"
        android:background="@drawable/optionsselector"
        android:textColor="@drawable/textcolorselector" />

    <Button
        android:id="@+id/option3"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/option2"
        android:layout_marginTop="30dp"
        android:background="@drawable/optionsselector"
        android:textColor="@drawable/textcolorselector" />

    <Button
        android:id="@+id/option4"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/option3"
        android:layout_marginTop="30dp"
        android:background="@drawable/optionsselector"
        android:textColor="@drawable/textcolorselector" />
</RelativeLayout>

<FrameLayout
    android:id="@+id/googleads"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true" >

    <com.google.ads.AdView
        xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
        android:id="@+id/adView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId=""
        ads:loadAdOnCreate="true" />
</FrameLayout>

</RelativeLayout>

Solution

  • For 10" tablet screen put your layout in layout-sw720dp and for 7" tablet put your layout in layout-sw600dp and look at the developer site in this link ,there is good enough info for your problem and also look at the useful info here.