如何使两种不同的布局,有相同的高度? [英] How to make two different layout to have same height?

查看:127
本文介绍了如何使两种不同的布局,有相同的高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序的XML布局,我有一个RelativeLayout的,其中有两个线性布局。我现在做的这两个布局动画。但由于尊者似乎高度不同我有一些看法的问题。

所以,我想使这两个布局相同的高度。下面是我的XML文件。

 <! -  ================================= ============================  - >
            <! - 瓶/ PEN布局 - >
            &所述;! - ============================================= ================ - >
            <的LinearLayout机器人:layout_height =WRAP_CONTENT
                机器人:layout_width =FILL_PARENT>                < RelativeLayout的机器人:layout_height =WRAP_CONTENT
                    机器人:layout_width =FILL_PARENT>
                    &所述;! - ============================================= ================ - >
                    <! - PEN布局 - >
                    &所述;! - ============================================= ================ - >
                    <的LinearLayout机器人:方向=垂直
                        机器人:layout_height =WRAP_CONTENT
                        机器人:layout_width =FILL_PARENT
                        机器人:ID =@ + ID / pen_layout>                        <的TextView
                            机器人:文字=EF
                            机器人:layout_height =WRAP_CONTENT
                            机器人:layout_width =WRAP_CONTENT
                            机器人:layout_gravity =中心
                            机器人:文字颜色=#000000
                            机器人:layout_marginTop =2DP
                            机器人:TEXTSIZE =10SP/>                        < ImageView的
                            机器人:ID =@ + ID /保存
                            机器人:layout_width =WRAP_CONTENT
                            机器人:layout_height =WRAP_CONTENT
                            机器人:layout_gravity =右
                            机器人:SRC =@绘制/ ink_pen/>                        <的TextView
                            机器人:文字=F
                            机器人:layout_height =WRAP_CONTENT
                            机器人:layout_width =WRAP_CONTENT
                            机器人:layout_gravity =中心
                            机器人:文字颜色=#000000
                            机器人:layout_marginTop =2DP
                            机器人:TEXTSIZE =10SP/>
                        < ImageView的
                            机器人:ID =@ + ID /保存
                            机器人:layout_width =WRAP_CONTENT
                            机器人:layout_height =WRAP_CONTENT
                            机器人:layout_gravity =右
                            机器人:SRC =@绘制/ ink_pen/>                        <的TextView
                            机器人:文字=大胆
                            机器人:layout_height =WRAP_CONTENT
                            机器人:layout_width =WRAP_CONTENT
                            机器人:layout_gravity =中心
                            机器人:文字颜色=#000000
                            机器人:layout_marginTop =2DP
                            机器人:TEXTSIZE =10SP/>
                        < ImageView的
                            机器人:ID =@ + ID /保存
                            机器人:layout_width =WRAP_CONTENT
                            机器人:layout_height =WRAP_CONTENT
                            机器人:layout_gravity =右
                            机器人:SRC =@绘制/ ink_pen/>                        <的TextView
                            机器人:文字=斜体
                            机器人:layout_height =WRAP_CONTENT
                            机器人:layout_width =WRAP_CONTENT
                            机器人:layout_gravity =中心
                            机器人:文字颜色=#000000
                            机器人:layout_marginTop =2DP
                            机器人:TEXTSIZE =10SP/>
                        < ImageView的
                            机器人:ID =@ + ID /保存
                            机器人:layout_width =WRAP_CONTENT
                            机器人:layout_height =WRAP_CONTENT
                            机器人:layout_gravity =右
                            机器人:SRC =@绘制/ ink_pen/>                    < / LinearLayout中>                    &所述;! - ============================================= ================ - >
                    <! - 瓶布局 - >
                    &所述;! - ============================================= ================ - >                    <的LinearLayout机器人:方向=垂直
                        机器人:layout_height =WRAP_CONTENT
                        机器人:layout_width =FILL_PARENT
                        机器人:weightSum =4
                        机器人:ID =@ + ID / bottle_layout>                        <! - 第一行瓶 - >
                        <的LinearLayout机器人:方向=横向
                            机器人:layout_height =WRAP_CONTENT机器人:layout_weight =1
                            机器人:layout_width =FILL_PARENT机器人:weightSum =2>
                            < ImageView的机器人:layout_height =WRAP_CONTENT机器人:layout_weight =1
                                机器人:layout_width =WRAP_CONTENT机器人:SRC =@绘制/ purple_bottle/>
                            < ImageView的机器人:layout_height =WRAP_CONTENT机器人:layout_weight =1
                                机器人:layout_width =WRAP_CONTENT机器人:SRC =@绘制/ red_bottle/>
                        < / LinearLayout中>                        <! - 第二排瓶 - >
                        <的LinearLayout机器人:方向=横向
                            机器人:layout_height =WRAP_CONTENT机器人:layout_weight =1
                            机器人:layout_width =FILL_PARENT机器人:weightSum =2>
                            < ImageView的机器人:layout_height =WRAP_CONTENT机器人:layout_weight =1
                                机器人:layout_width =WRAP_CONTENT机器人:SRC =@绘制/ gray_bottle/>
                            < ImageView的机器人:layout_height =WRAP_CONTENT机器人:layout_weight =1
                                机器人:layout_width =WRAP_CONTENT机器人:SRC =@绘制/ green_bottle/>
                        < / LinearLayout中>                        <! - 第三排瓶 - >
                        <的LinearLayout机器人:方向=横向
                            机器人:layout_height =WRAP_CONTENT机器人:layout_weight =1
                                机器人:layout_width =FILL_PARENT机器人:weightSum =2>
                            < ImageView的机器人:layout_height =WRAP_CONTENT机器人:layout_weight =1
                                机器人:layout_width =WRAP_CONTENT机器人:SRC =@绘制/ orange_bottle/>
                            < ImageView的机器人:layout_height =WRAP_CONTENT机器人:layout_weight =1
                                机器人:layout_width =WRAP_CONTENT机器人:SRC =@绘制/ blue_bottle/>
                        < / LinearLayout中>                        <! - 第四排瓶 - >
                        <的LinearLayout机器人:方向=横向
                            机器人:layout_height =WRAP_CONTENT机器人:layout_weight =1
                            机器人:layout_width =FILL_PARENT机器人:weightSum =2>
                            < ImageView的机器人:layout_height =WRAP_CONTENT机器人:layout_weight =1
                                机器人:layout_width =WRAP_CONTENT机器人:SRC =@绘制/ black_bottle/>
                            < ImageView的机器人:layout_height =WRAP_CONTENT机器人:layout_weight =1
                                机器人:layout_width =WRAP_CONTENT机器人:SRC =@绘制/ white_bottle/>
                        < / LinearLayout中>                    < / LinearLayout中>
                < / RelativeLayout的>
            < / LinearLayout中>


解决方案

删除包含RelativeLayout的(因为它是你的根的独子的LinearLayout你不严格需要它)或将其更改为LinearLayout中。

然后同时为笔布局和瓶子布局,添加属性android:layout_weight并把它们设置为1。

确认,无论是布局具有高度设置为MATCH_PARENT

现在你的两个布局应该平等地分享空间之间,从而使它们在同一高度。

要共享相同的笔和一瓶布局的孩子之间的空间,我建议你设定每个孩子的高度和WRAP_CONTENT每个儿童为1。layout_weight

In My application xml layout, i have one Relativelayout, In which there are two linear Layout. Now i am doing the animation for that both layout. But because thera seems the height different i got some view problem.

So i want to make the same height of the both layout. below is my xml file.

<!-- ============================================================= -->
            <!-- BOTTLE / PEN LAYOUT -->
            <!-- ============================================================= -->
            <LinearLayout android:layout_height="wrap_content"
                android:layout_width="fill_parent" >

                <RelativeLayout android:layout_height="wrap_content"
                    android:layout_width="fill_parent">
                    <!-- ============================================================= -->
                    <!-- PEN LAYOUT -->
                    <!-- ============================================================= -->
                    <LinearLayout android:orientation="vertical"
                        android:layout_height="wrap_content"
                        android:layout_width="fill_parent"
                        android:id="@+id/pen_layout">

                        <TextView
                            android:text="EF"
                            android:layout_height="wrap_content"
                            android:layout_width="wrap_content"
                            android:layout_gravity="center"
                            android:textColor="#000000"
                            android:layout_marginTop="2dp"
                            android:textSize="10sp"/>

                        <ImageView                 
                            android:id="@+id/save"                 
                            android:layout_width="wrap_content"                 
                            android:layout_height="wrap_content"
                            android:layout_gravity="right"   
                            android:src="@drawable/ink_pen"/>             

                        <TextView
                            android:text="F"
                            android:layout_height="wrap_content"
                            android:layout_width="wrap_content"
                            android:layout_gravity="center"
                            android:textColor="#000000"
                            android:layout_marginTop="2dp"
                            android:textSize="10sp"/>
                        <ImageView                 
                            android:id="@+id/save"                 
                            android:layout_width="wrap_content"                 
                            android:layout_height="wrap_content"
                            android:layout_gravity="right"   
                            android:src="@drawable/ink_pen"/>             

                        <TextView
                            android:text="BOLD"
                            android:layout_height="wrap_content"
                            android:layout_width="wrap_content"
                            android:layout_gravity="center"
                            android:textColor="#000000"
                            android:layout_marginTop="2dp"
                            android:textSize="10sp"/>
                        <ImageView                 
                            android:id="@+id/save"                 
                            android:layout_width="wrap_content"                 
                            android:layout_height="wrap_content"
                            android:layout_gravity="right"   
                            android:src="@drawable/ink_pen"/>             

                        <TextView
                            android:text="ITALIC"
                            android:layout_height="wrap_content"
                            android:layout_width="wrap_content"
                            android:layout_gravity="center"
                            android:textColor="#000000"
                            android:layout_marginTop="2dp"
                            android:textSize="10sp"/>
                        <ImageView                 
                            android:id="@+id/save"                 
                            android:layout_width="wrap_content"                 
                            android:layout_height="wrap_content"
                            android:layout_gravity="right"   
                            android:src="@drawable/ink_pen"/>

                    </LinearLayout> 

                    <!-- ============================================================= -->
                    <!-- BOTTLE LAYOUT -->
                    <!-- ============================================================= -->

                    <LinearLayout android:orientation="vertical"
                        android:layout_height="wrap_content"
                        android:layout_width="fill_parent"
                        android:weightSum="4" 
                        android:id="@+id/bottle_layout">

                        <!-- First Row Bottle -->
                        <LinearLayout android:orientation="horizontal"
                            android:layout_height="wrap_content" android:layout_weight="1"
                            android:layout_width="fill_parent" android:weightSum="2">
                            <ImageView android:layout_height="wrap_content" android:layout_weight="1"
                                android:layout_width="wrap_content" android:src="@drawable/purple_bottle"/>
                            <ImageView android:layout_height="wrap_content" android:layout_weight="1"
                                android:layout_width="wrap_content" android:src="@drawable/red_bottle"/>
                        </LinearLayout>

                        <!-- Second Row Bottle -->              
                        <LinearLayout android:orientation="horizontal"
                            android:layout_height="wrap_content" android:layout_weight="1"
                            android:layout_width="fill_parent" android:weightSum="2">
                            <ImageView android:layout_height="wrap_content" android:layout_weight="1"
                                android:layout_width="wrap_content" android:src="@drawable/gray_bottle"/>
                            <ImageView android:layout_height="wrap_content" android:layout_weight="1"
                                android:layout_width="wrap_content" android:src="@drawable/green_bottle"/>
                        </LinearLayout>

                        <!-- Third Row Bottle -->               
                        <LinearLayout android:orientation="horizontal"
                            android:layout_height="wrap_content" android:layout_weight="1"
                                android:layout_width="fill_parent" android:weightSum="2">
                            <ImageView android:layout_height="wrap_content" android:layout_weight="1"
                                android:layout_width="wrap_content" android:src="@drawable/orange_bottle"/>
                            <ImageView android:layout_height="wrap_content" android:layout_weight="1"
                                android:layout_width="wrap_content" android:src="@drawable/blue_bottle"/>
                        </LinearLayout>

                        <!-- Forth Row Bottle -->               
                        <LinearLayout android:orientation="horizontal"
                            android:layout_height="wrap_content" android:layout_weight="1"
                            android:layout_width="fill_parent" android:weightSum="2">
                            <ImageView android:layout_height="wrap_content" android:layout_weight="1"
                                android:layout_width="wrap_content" android:src="@drawable/black_bottle"/>
                            <ImageView android:layout_height="wrap_content" android:layout_weight="1"
                                android:layout_width="wrap_content" android:src="@drawable/white_bottle"/>
                        </LinearLayout>

                    </LinearLayout>
                </RelativeLayout>
            </LinearLayout>

解决方案

Delete the containing RelativeLayout (since it is the only child of your root LinearLayout you don't strictly need it) or change it to a LinearLayout.

Then for both the Pen layout and the bottle layout, add the attribute android:layout_weight and set them both to 1.

Make sure that both the layouts have the height set to MATCH_PARENT

Now your two layouts should share the space equally between them, thus making them the same height.

To share the space equally between the children of the Pen and Bottle layouts, I suggest that you set the height of each child to WRAP_CONTENT and the layout_weight of each child to 1.

这篇关于如何使两种不同的布局,有相同的高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆