布局不是以不同的屏幕尺寸正确定位

时间:2016-02-20 05:19:26

标签: android relativelayout

我想通过点击在图像上方显示两个图像。

Desired layout

实际上它会在页脚中使用我的应用程序。我为此做了布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="100dp">

    <!-- add content menu layout -->
    <RelativeLayout
        android:id="@+id/relativeLayout1"
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="2dp"
        android:layout_marginRight="70dp"
        android:visibility="visible">

        <ImageView
            android:id="@+id/createQuizImage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@android:color/black"
            android:padding="10dp"
            android:src="@drawable/icon_create_quiz" />

        <ImageView
            android:id="@+id/createPollImage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="3dp"
            android:layout_marginStart="3dp"
            android:layout_toEndOf="@+id/createQuizImage"
            android:layout_toRightOf="@+id/createQuizImage"
            android:background="@android:color/black"
            android:padding="10dp"
            android:src="@drawable/icon_create_poll" />
    </RelativeLayout>

    <!-- single or team leaderboard menu layout -->
    <RelativeLayout
        android:id="@+id/relativeLayout2"
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="2dp"
        android:layout_marginRight="25dp"
        android:visibility="invisible">

        <ImageView
            android:id="@+id/individualRankImage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@android:color/black"
            android:padding="10dp"
            android:src="@drawable/icon_single_leaderboard" />

        <ImageView
            android:id="@+id/groupRankImage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="3dp"
            android:layout_marginStart="3dp"
            android:layout_toEndOf="@+id/individualRankImage"
            android:layout_toRightOf="@+id/individualRankImage"
            android:background="@android:color/black"
            android:padding="10dp"
            android:src="@drawable/icon_team_leaderboard" />
    </RelativeLayout>

    <!-- footer toolbar -->
    <RelativeLayout
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="45dp"
        android:layout_below="@+id/relativeLayout1"
        android:background="?attr/colorPrimary">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ImageView
                android:id="@+id/menuImageView"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_centerVertical="true"
                android:layout_marginLeft="10dp"
                android:src="@drawable/icon_menu" />

            <ImageView
                android:id="@+id/createContentImage"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_toLeftOf="@+id/starImageView"
                android:src="@drawable/icon_plus1" />


            <ImageView
                android:id="@+id/starImageView"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_toLeftOf="@+id/scheduleImageView"
                android:src="@drawable/icon_star1" />

            <ImageView
                android:id="@+id/scheduleImageView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:src="@drawable/icon_match_up1" />

            <ImageView
                android:id="@+id/micImageView"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_alignParentRight="true"
                android:src="@drawable/icon_mic1"
                android:visibility="gone" />
        </RelativeLayout>
    </RelativeLayout>
</RelativeLayout>

但是relativeLayout1在不同的屏幕尺寸中没有正确定位。请有人告诉我一个适当的方法来处理所有屏幕。

4 个答案:

答案 0 :(得分:0)

您必须手动为不同的屏幕尺寸进行布局。您不应期望在所有屏幕尺寸上只有一个布局看起来相同。有关更多详细信息,请参阅以下文档。

Supporting Different Screen Sizes

Supporting Multiple Screens

答案 1 :(得分:0)

你好! 做一件事...尝试使用weightsum并使用LinearLayout进行设计。这肯定会对你有所帮助!

要了解权重,请点击以下链接:What is android:weightSum in android, and how does it work?

如果您对此仍然感到困惑,请告诉我。:)

答案 2 :(得分:0)

根据分辨率和

,您必须遵循此操作以支持多个设备

根据设备提供填充,边距,字体和所有属性。

即使你使用weightSum,你也需要关注

屏幕密度的变化。

nil

制作此布局文件,以使其对所有设备都相同。

xlarge screens are at least 960dp x 720dp
large screens are at least 640dp x 480dp
normal screens are at least 470dp x 320dp
small screens are at least 426dp x 320dp

用于图像

res/layout/main_activity.xml           # For handsets (smaller than 600dp available width)
res/layout-sw600dp/main_activity.xml   # For 7” tablets (600dp wide and bigger)
res/layout-sw720dp/main_activity.xml   # For 10” tablets (720dp wide and bigger)
For Layout ,

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

For Icon

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

请访问Supporting Multiple Screens

答案 3 :(得分:0)

如果您为所有设备设置相同的布局,则为不同分辨率创建单独布局文件夹的想法毫无价值。它会增加.apk的大小。最好的方法是在'res'文件夹下定义不同分辨率设备的维度值,并将其用于布局文件而不是使用直接值。

res / values-swXXXdp 文件夹下创建单独的dimens.xml文件,其中XXX的值对于手机型号为(320,480),对于平板电脑型号为(600,720,800)。通过这种方式,您可以为不同的屏幕大小定义必要的维度值,并从单个公共布局文件中引用它们。

希望这会有所帮助!!

相关问题