Apply scale to layout in android

I have a RelativeLayout which currently has a fixed size. Widths, heights, margins, font heights of child views are specified so everything looks just right.

I now want to scale the layout (to fit screen size). The layout should scale as if it was a flat image, so everything gets smaller in proportion (fonts, margins etc.)

I made a simplified example, below. Scaled to 0.5, this would display the text "ONE QUARTER" with margin left 200dip and margin top 120dip.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
    android:id="@+id/RelativeLayout01"
    android:layout_width="1600dip" 
    android:layout_height="960dip"
    xmlns:android="http://schemas.android.com/apk/res/android"
>
<TextView 
    android:text="ONE QUARTER" 
    android:id="@+id/TextView01" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:layout_marginLeft="400dip"
    android:layout_marginTop="240dip"
></TextView>
</RelativeLayout>

Of course, I'm not asking anyone to help me hand code an algorithm to scale all these values: just wondering if there's some simple way to achieve this...

Thanks!


If you just want your app to look ok on another device then specifying things in dip and sp should do the trick.

If you actually want to shrink or expand the scale of your app on the same device then you would have to do it manually, perhaps using themes or styles.

链接地址: http://www.djcxy.com/p/59802.html

上一篇: 自定义安装的字体在UILabel中显示不正确

下一篇: 在android中将比例应用于布局