Android布局内部视图保持所有设备的比例

时间:2015-05-05 10:22:50

标签: android layout positioning

我正在实施此Layout

enter image description here

它包含手机内的Background ImagePhone Image和白色white view。那个是gif animation

这是我的代码:

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

<ImageView
    android:id="@+id/image"
    android:background="@drawable/empty_background"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/iphone_background">


<pl.droidsonroids.gif.GifImageView
    android:id="@+id/inner_image"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginLeft="140dp"
    android:layout_marginTop="240dp"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true" />

</RelativeLayout>

Nexus 5 Lollipop 5.0看起来很好,但每个分辨率的Inner View(gif)看起来都不一样。

任何帮助都会很棒,谢谢:)

2 个答案:

答案 0 :(得分:0)

嗯这需要比特计算,你可以使用pixplicity.com并为不同尺寸的屏幕计算不同的dp尺寸。

例如:

如果xhdpi的原始图像尺寸为640 * 480像素,那么对于其他图像尺寸为

长度:

ldpi @ 320.00dp = 240.00px = 320.00sp = 50.80mm = 2.00in = 144.00pt

mdpi @ 320.00dp = 320.00px = 320.00sp = 50.80mm = 2.00in = 144.00pt

tvdpi @ 320.00dp = 426.00px = 320.00sp = 50.80mm = 2.00in = 144.00pt

hdpi @ 320.00dp = 480.00px = 320.00sp = 50.80mm = 2.00in = 144.00pt

xhdpi @ 320.00dp = 640.00px = 320.00sp = 50.80mm = 2.00in = 144.00pt

xxhdpi @ 320.00dp = 960.00px = 320.00sp = 50.80mm = 2.00in = 144.00pt

xxxhdpi @ 320.00dp = 1280.00px = 320.00sp = 50.80mm = 2.00in = 144.00pt

和广度:

ldpi @ 240.00dp = 180.00px = 240.00sp = 38.10mm = 1.50in = 108.00pt

mdpi @ 240.00dp = 240.00px = 240.00sp = 38.10mm = 1.50in = 108.00pt

tvdpi @ 240.00dp = 319.50px = 240.00sp = 38.10mm = 1.50in = 108.00pt

hdpi @ 240.00dp = 360.00px = 240.00sp = 38.10mm = 1.50in = 108.00pt

xhdpi @ 240.00dp = 480.00px = 240.00sp = 38.10mm = 1.50in = 108.00pt

xxhdpi @ 240.00dp = 720.00px = 240.00sp = 38.10mm = 1.50in = 108.00pt

xxxhdpi @ 240.00dp = 960.00px = 240.00sp = 38.10mm = 1.50in = 108.00pt

并且你需要为所有不同的图像保存相同的gif名称,并将它们相应地放在相应的可绘制文件夹中(mdpi,hdpi,xhdpi,xxhdpi)。

答案 1 :(得分:0)

Background Image可以采用match_parent尺寸。但是,对于Phone ImageGIF Image,请尝试将每个尺寸分开放在一个LinearLayouts上 - 另外,并将layout_width设置为0dplayout_heightwrap_content,同时指定layout_weight以正确对齐视图,这可以使您的所有屏幕上的视图看起来都很相似。