Android:两个固定 LinearLayout 之间的拉伸布局
这是我的布局(图片):
https://i.sstatic.net/wPx04.jpg
我想做的是让第一个 LinearLayout 50dip 高(这已经可以了),然后让第三个 LinearLayout 从下往上也 50dip 高 - 然后让第二个 LinearLayout 填充这个地方留在中间。我该怎么做?
这是我的 XML:
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" >
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/linearLayout1"
android:orientation="vertical" >
<ViewFlipper
android:id="@+id/viewFlipper1"
android:layout_width="match_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/rain1" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/thunder1" />
</ViewFlipper>
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout3"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/linearLayout2">
</LinearLayout>
</RelativeLayout>
this is my layout (image):
https://i.sstatic.net/wPx04.jpg
What I want to do is make the 1st LinearLayout 50dip high (this is already OK), then have the 3rd LinearLayout also 50dip high from the bottom up - and then make the 2nd LinearLayout fill the place left inbetween. How do I do it?
This is my XML:
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" >
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/linearLayout1"
android:orientation="vertical" >
<ViewFlipper
android:id="@+id/viewFlipper1"
android:layout_width="match_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/rain1" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/thunder1" />
</ViewFlipper>
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout3"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/linearLayout2">
</LinearLayout>
</RelativeLayout>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
将所有三个布局包装在垂直线性布局中,并在中间布局上使用 布局权重 为“1”:
Wrap all three layouts in a vertical Linear Layout and use a layout weight of "1" on the middle layout:
我没有在此代码中添加您的绘图,但我相信这应该可以解决您的问题:
I haven't added your drawables in this code but I believe this should fix your problem:
将 LinearLayout 转换为相对布局。定义元素的相对位置。你的问题将会得到解决
或者在线性布局中使用权重。为第二个线性布局定义权重 1.0。对于顶部父布局,高度和宽度应为 fill_parent
Convert LinearLayout into Relative layout. define relative position of element. your problem will get solved
Or use weight in linear layout. define weight 1.0 for second linear layout.and for top parent layout height and width should be fill_parent
试试这个:
Try this:
尝试将第三个布局放在第二个布局之前
try put the 3rd layout before the 2nd one