0

我想将包含在相对布局中的内部布局设置为其包含的布局的特定百分比。如何将布局高度设置为特定百分比。另一个例子假设我有一个 ImageView,我希望它恰好占据它所在容器的 60%。我该如何指定?我确实看到了:Android Layout Percentage/Proportion Resize这在一定程度上解释了这一点。但是,如果我想说 48%,我不确定调整重量是否有效?

4

1 回答 1

3

您需要使用LinearLayout属性android:layout_weigth.

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:weightSum="5"
    android:orientation="vertical" >
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="2" >

    <!-- Other elements here -->

    </RelativeLayout>
    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="3" />
</LinearLayout>

嵌套RelativeLayout将占用 2 / (2 + 3) = 0.4 (40%) 和ImageView3 / (2 + 3) = 0.6 (60%)。

于 2012-05-02T00:14:38.497 回答