2

帮助我进行 XML 布局。

我在活动中有三个 LinearLayout,所有 LinearLayout 的位置都是垂直的(从上到下)

我的 LinearLayout 职位

  1. 第一个 LinearLayout 有android:layout_height="30px", android:layout_width="fill_parent"
  2. 第二个 LinearLayout 有android:layout_height="fill_parent", android:layout_width="fill_parent"
  3. 第三个 LinearLayout 有android:layout_height="30px",android:layout_width="fill_parent"

但是当第二个 LinearLayout 设置为fill_parent时,它会填满全屏(从第一个布局到屏幕底部),而第三个 LinearLayout 无法显示!

我需要如何填充第二个布局?

帮我

4

5 回答 5

3

简单地使用这个。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/MainLinear"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:background="#fbfbfb"
android:orientation="vertical" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="30dp"
    android:orientation="horizontal" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.9"
    android:orientation="vertical" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="30dp"
    android:orientation="horizontal" />
</LinearLayout>
</LinearLayout>
于 2014-09-26T09:16:55.377 回答
2

您可以为您的目的使用相对布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="match_parent"
    android:layout_height="30dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:orientation="vertical" >
</LinearLayout>

<LinearLayout
    android:id="@+id/linearLayout2"
    android:layout_width="match_parent"
    android:layout_height="30dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:orientation="vertical" >
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/linearLayout1"
    android:layout_above="@+id/linearLayout2"
    android:orientation="vertical" >
</LinearLayout>

</RelativeLayout>
于 2014-09-26T09:11:11.710 回答
0

诀窍是不要使用它fill_parent,而是0dp给它一个权重android:layout_weight="1"。这意味着它将占用所有可用的额外空间

于 2014-09-26T09:11:08.227 回答
0

您必须为中间线性布局赋予重量,以便它可以占据整个高度。

try this for middle linear layout,

   <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1" >
    </LinearLayout>
于 2014-09-26T09:11:59.463 回答
0

如果将 height="fill_parent" 设置为中间布局,它将采用父视图的高度,因此第 3 个视图将不可见(超出屏幕)

1st layout : android:layout_height="30px", android:layout_width="match_parent"
2nd layout : android:layout_height="0dp", android:layout_width="match_parent", android:layout_weight="1"
3rd layout : android:layout_height="30px", android:layout_width="match_parent"

您应该使用“dp”而不是“px”,以在不同的屏幕密度上获得相同的尺寸。

(“fill_parent”已弃用,您应该使用“match_parent”,它的作用相同)

于 2014-09-26T09:14:00.263 回答