Android:两个固定 LinearLayout 之间的拉伸布局

发布于 2025-01-01 12:46:47 字数 1832 浏览 7 评论 0原文

这是我的布局(图片):

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

我做我的改变 2025-01-08 12:46:47

将所有三个布局包装在垂直线性布局中,并在中间布局上使用 布局权重 为“1”:

<LinearLayout
    .
    .
    . 
    android:layout_height="fill_parent"
    android:orientation="vertical">
    <LinearLayout 
        .
        .
        .
        android:layout_height="50dip">
    <LinearLayout 
        .
        .
        .
        android:layout_height="0dp"
        android:layout_weight="1">
    <LinearLayout 
        .
        .
        .
        android:layout_height="50dip">
</LinearLayout>

Wrap all three layouts in a vertical Linear Layout and use a layout weight of "1" on the middle layout:

<LinearLayout
    .
    .
    . 
    android:layout_height="fill_parent"
    android:orientation="vertical">
    <LinearLayout 
        .
        .
        .
        android:layout_height="50dip">
    <LinearLayout 
        .
        .
        .
        android:layout_height="0dp"
        android:layout_weight="1">
    <LinearLayout 
        .
        .
        .
        android:layout_height="50dip">
</LinearLayout>
一瞬间的火花 2025-01-08 12:46:47

我没有在此代码中添加您的绘图,但我相信这应该可以解决您的问题:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativeLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="50dp"
    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:layout_above="@+id/linearLayout3"
    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"
            />

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            />

    </ViewFlipper>

</LinearLayout>

<LinearLayout
    android:id="@+id/linearLayout3"
    android:layout_width="fill_parent"
    android:layout_height="50dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true" >

</LinearLayout>


</RelativeLayout>

I haven't added your drawables in this code but I believe this should fix your problem:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativeLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="50dp"
    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:layout_above="@+id/linearLayout3"
    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"
            />

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            />

    </ViewFlipper>

</LinearLayout>

<LinearLayout
    android:id="@+id/linearLayout3"
    android:layout_width="fill_parent"
    android:layout_height="50dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true" >

</LinearLayout>


</RelativeLayout>
痞味浪人 2025-01-08 12:46:47

将 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

白云不回头 2025-01-08 12:46:47

试试这个:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
              android:orientation="vertical" 
              android:layout_width="fill_parent" 
              android:layout_height="fill_parent"
              >
    <LinearLayout 
        android:layout_width="fill_parent" 
        android:layout_height="50dip" 
        android:background="#FF00FF"    
        android:id="@+id/first"    
        />   
     <LinearLayout 
        android:layout_width="fill_parent" 
        android:layout_height="50dip" 
        android:background="#0000FF"
        android:id="@+id/last"    
        android:layout_alignParentBottom="true"         
       />        
     <LinearLayout 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:background="#FFFFFF"
        android:layout_above="@id/last" 
        android:layout_below="@id/first"    
        >
        <ViewFlipper
            android:id="@+id/viewFlipper1"
            android:layout_width="fill_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>
</RelativeLayout>

Try this:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
              android:orientation="vertical" 
              android:layout_width="fill_parent" 
              android:layout_height="fill_parent"
              >
    <LinearLayout 
        android:layout_width="fill_parent" 
        android:layout_height="50dip" 
        android:background="#FF00FF"    
        android:id="@+id/first"    
        />   
     <LinearLayout 
        android:layout_width="fill_parent" 
        android:layout_height="50dip" 
        android:background="#0000FF"
        android:id="@+id/last"    
        android:layout_alignParentBottom="true"         
       />        
     <LinearLayout 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:background="#FFFFFF"
        android:layout_above="@id/last" 
        android:layout_below="@id/first"    
        >
        <ViewFlipper
            android:id="@+id/viewFlipper1"
            android:layout_width="fill_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>
</RelativeLayout>
久夏青 2025-01-08 12:46:47
LinearLayout layout;
layout.addView(child, 2);
LinearLayout layout;
layout.addView(child, 2);
格子衫的從容 2025-01-08 12:46:47

尝试将第三个布局放在第二个布局之前

<Relativelayout>
    <Linearlayout1>
    <Linearlayout3>
    <linearlayout2>
</Relativelayout>

try put the 3rd layout before the 2nd one

<Relativelayout>
    <Linearlayout1>
    <Linearlayout3>
    <linearlayout2>
</Relativelayout>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文