Android:布局比例缩放

时间:2016-11-18 12:18:28

标签: android android-layout

我想在Android设备上模拟微控制器屏幕(800x480)。屏幕内容是按钮,标签,图形基元(线,矩形......),图像。 如何在所有屏幕上进行布局(放大/缩小)?

这是布局xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="800px"
android:minHeight="480px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/rootLayout"
android:gravity="center">
<LinearLayout
    android:orientation="horizontal"
    android:minWidth="800px"
    android:minHeight="480px"
    android:layout_width="800px"
    android:layout_height="480px"
    android:id="@+id/mainContainer">
  <NSU.Droid.MyWindow
      android:minWidth="714px"
      android:layout_width="714px"
      android:layout_height="match_parent"
      android:id="@+id/mainWindow"
      android:background="@drawable/window_shape"
      android:layout_margin="1dp" />
  <LinearLayout
      android:minWidth="86px"
      android:layout_width="86px"
      android:layout_height="match_parent"
      android:background="@drawable/sidewindow_shape"
      android:layout_margin="1px"
      android:scrollbars="none">
    <ScrollView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
      <NSU.Droid.SideWindow
          android:orientation="vertical"
          android:minWidth="86px"
          android:layout_width="86px"
          android:layout_height="wrap_content"
          android:id="@+id/sideWindow"
          android:scrollbars="none" />
    </ScrollView>
  </LinearLayout>
</LinearLayout>

NSU.Droid.MyWindow是RelativeLayout 如果使用px,模拟布局太小,在我的设备屏幕上约为1/3。将px更改为dp无济于事 - 视图太大,我可以看到大约2/3的布局内容 如何按比例缩放布局和内容?

1 个答案:

答案 0 :(得分:0)

使用match_parent android:layour_widthandroid:layout_height属性来适应屏幕布局。 要使项目大小成比例,您可以使用android:layout_weight中的LinearLayout属性。

例如:

<LinearLayout 
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:orientation="horizontal">
    <FrameLayout android:layout_width="0dp" android:layout_height="match_parent"
        android:background="#ff0000"
        android:layout_weight="3" />
    <FrameLayout android:layout_width="0dp" android:layout_height="match_parent"
        android:background="#0000ff"
        android:layout_weight="1" />
</LinearLayout>

如果您的LinearLayout具有水平方向,则应将android:layout_width属性设置为0dp,以将LinearLayout的元素设置为您要应用的android:layout_weight LinearLayout属性。如果android:layout_height的方向是垂直的,那么0dp属性应设置为WITH TEST_DATA AS ( SELECT 1 AS ID, 'ALUM' AS DONOR_CODE, 1 AS PRIORITY FROM DUAL UNION SELECT 1 AS ID, 'STAFF' AS DONOR_CODE, 2 AS PRIORITY FROM DUAL UNION SELECT 8 AS ID, 'ALUM' AS DONOR_CODE, 1 AS PRIORITY FROM DUAL UNION SELECT 8 AS ID, 'ALMG' AS DONOR_CODE, 2 AS PRORITY FROM DUAL UNION SELECT 8 AS ID, 'STAF' AS DONOR_CODE, 3 AS PRORITY FROM DUAL ) , PIVOT_DATA AS ( SELECT * FROM TEST_DATA PIVOT (MAX(DONOR_CODE) AS DONOR_CODE FOR PRIORITY IN (1,2,3) ) ) SELECT * FROM PIVOT_DATA;

上面的XML应如下所示:

Weights