如何在Android中的5.4英寸,7英寸和10.1英寸屏幕上设置UI?

时间:2013-12-23 11:02:55

标签: android user-interface screens

我正在尝试在超大屏幕上设置用户界面,即5.4英寸,7英寸和10.1英寸。我无法在以下屏幕上设置用户界面。因为我在layout-xhdpi中设置其界面,但它正在选择layout-mdpi。请指导我如何解决这个问题。

这个是layout-mdpi代码

<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>

此代码适用于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>

1 个答案:

答案 0 :(得分:0)

对于10英寸平板电脑屏幕,将布局放在layout-sw720dp和7英寸平板电脑上,将布局放在layout-sw600dp中,并查看此link中的开发者网站,有足够的信息来解决您的问题。另请查看有用信息here