[英]Android: location of the an ImageView Changes on different sizes screen Android
[英]Android: ImageView's Location Changes on different sizes screen
我的布局中有五個圖像視圖,應該將每個圖像視圖放在背景上的特定位置。 在不同屏幕尺寸上運行我的應用程序時,圖像視圖的位置會上移。 我創建以下文件夾。
分辨率/布局-小
分辨率/布局正常
res / layout-large
分辨率/布局-xlarge
在這里您可以找到我的布局。
<?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>
res / layout / your_layout.xml //正常屏幕尺寸的布局(“默認”)
res / layout-large / your_layout.xml //大屏幕布局
res / layout-xlarge / your_layout.xml //用於超大屏幕尺寸的布局
res / layout-xlarge-land / your_layout.xml //用於橫向放置的布局
並在每個文件夾中..具有不同圖像位置的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會調整應用程序布局的大小以適合當前設備的屏幕。 在大多數情況下,這可以正常工作。 在其他情況下,您的UI可能看起來不那么好,可能需要針對不同的屏幕尺寸進行調整。 例如,在較大的屏幕上,您可能需要調整某些元素的位置和大小以利用額外的屏幕空間,或者在較小的屏幕上,可能需要調整大小以使所有內容都適合屏幕。
可用於提供特定於大小的資源的配置限定符為small,normal,large和xlarge。 例如,超大屏幕的布局應放在layout-xlarge /中。
從Android 3.2(API級別13)開始,不建議使用上述大小組,而應使用sw <N> dp配置限定符定義布局資源所需的最小可用寬度。 例如,如果您的多窗格平板電腦布局需要至少600dp的屏幕寬度,則應將其放置在layout-sw600dp /中 。 關於聲明Android 3.2平板電腦布局的部分中,將進一步討論使用新技術聲明布局資源。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.