2016-02-27 82 views
0

我的布局中有五个图像视图,我应该将每个图像视图放在背景上的特定位置。在不同的屏幕尺寸上运行我的应用程序时,图像视图的位置向上移动。 我创建了以下文件夹。
res/layout- small
res/layout-normal
res/layout-large
res/layout-xlarge
在这里您可以找到我的布局。Android:ImageView的位置在不同尺寸屏幕上的更改

<?xml version="1.0" encoding="utf-8"?> 
<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"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/body" 
     android:layout_below="@+id/header" 
     android:background="@drawable/upn"> 

     <ImageView 
      android:layout_width="45dip" 
      android:layout_height="20dip" 
      android:id="@+id/U1" 
      android:layout_gravity="center" 
      android:background="#f40c0d" 
      android:padding="1dip" 
      android:layout_marginRight="26dip" 
      android:layout_marginEnd="26dip" 
      android:layout_marginBottom="96dip" 
      android:layout_above="@+id/U5" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentEnd="true" /> 

     <ImageView 
      android:layout_width="45dip" 
      android:layout_height="20dip" 
      android:id="@+id/U3" 
      android:layout_gravity="center" 
      android:background="#f40c0d" 
      android:padding="1dip" 
      android:layout_marginRight="63dip" 
      android:layout_marginEnd="63dip" 
      android:layout_above="@+id/U1" 
      android:layout_toLeftOf="@+id/U1" 
      android:layout_toStartOf="@+id/U1" 
      android:layout_marginBottom="22dip" /> 


     <ImageView 
      android:layout_width="45dip" 
      android:layout_height="20dip" 
      android:id="@+id/U2" 
      android:layout_gravity="center" 
      android:background="#f40c0d" 
      android:padding="1dip" 
      android:layout_marginRight="5dip" 
      android:layout_marginEnd="5dip" 
      android:layout_marginBottom="103dip" 
      android:layout_alignParentBottom="true" 
      android:layout_alignRight="@+id/U3" 
      android:layout_alignEnd="@+id/U3" 
      /> 

     <ImageView 
      android:layout_width="45dip" 
      android:layout_height="20dip" 
      android:id="@+id/U4" 
      android:layout_gravity="center" 
      android:background="#f40c0d" 
      android:padding="1dip" 
      android:layout_above="@+id/U2" 
      android:layout_alignLeft="@+id/U5" 
      android:layout_alignStart="@+id/U5" 
      android:layout_marginBottom="18dip" 
      /> 

     <ImageView 
      android:layout_width="45dip" 
      android:layout_height="20dip" 
      android:id="@+id/U5" 
      android:layout_gravity="center" 
      android:background="#f40c0d" 
      android:padding="1dip" 
      android:layout_marginLeft="68dip" 
      android:layout_marginStart="68dp" 
      android:layout_above="@+id/U2" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" 
      android:layout_marginBottom="43dp" 
      /> 

    </RelativeLayout> 
</RelativeLayout> 
+0

我敢肯定,这些名称是不正确的布局。 – durbnpoisn

+0

每个布局只有一个图像?比你只需要5个不同的布局与一个图像视图..每个布局应该包含相同的图像视图ID –

+0

@durbnpoisn,我从这里得到这些文件夹名称[链接](http://developer.android.com/guide/practices/ screens_support.html#dips-pels) –

回答

0

RES /布局/ your_layout.xml //布局正常屏幕尺寸( “默认”)

RES /布局大/ your_layout.xml //布局大屏幕尺寸

RES /布局XLARGE/your_layout.xml //布局超大屏幕尺寸

01在横向

RES /布局XLARGE土地/ your_layout.xml //布局超大

和每个文件夹中..the不同图像的your_layout.xml定位

例如。 RES/layout_large/your_layout.xml

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/body" 
    android:layout_below="@+id/header" 
    android:background="@drawable/upn"> 

    <ImageView 
     android:id="@+id/my_iv" 
     ..... 
    /> 
</RelativeLayout> 

也许你必须在你的清单文件中添加此行

<supports-screens android:smallScreens="true" 
      android:normalScreens="true" 
      android:largeScreens="true" 
      android:xlargeScreens="true" 
      android:anyDensity="true" /> 

//更多信息:

http://developer.android.com/guide/practices/screens_support.html#support

为不同的屏幕尺寸提供不同的布局 默认情况下,Android调整您的应用程序布局以适合当前设备屏幕。在大多数情况下,这工作正常。在其他情况下,您的用户界面可能看起来不太好,可能需要针对不同的屏幕尺寸进行调整。例如,在较大的屏幕上,您可能需要调整某些元素的位置和大小以利用额外的屏幕空间,或者在较小的屏幕上,可能需要调整大小以使所有内容都可以放在屏幕上。
可用于提供特定大小的资源的配置限定符是small,normal,large和xlarge。例如,超大屏幕的布局应该放在layout-xlarge /中。

从Android 3.2(API级别13)开始,上面的大小组已被弃用,您应该使用swp <d> dp配置限定符来定义布局资源所需的最小可用宽度。例如,如果多窗格平板电脑布局需要至少600dp的屏幕宽度,则应将其置于layout-sw600dp/。关于为Android 3.2声明平板布局的部分将进一步讨论使用新技术来声明布局资源。