android – 如何为包含的布局设置权重?

android – 如何为包含的布局设置权重?,第1张

概述我有两个xml文件,页眉和页脚,如下所示 header.xml <?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layo 我有两个xml文件,页眉和页脚,如下所示

header.xml

<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_wIDth="match_parent"    androID:layout_height="wrap_content"    androID:orIEntation="vertical" >    <linearLayout        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:background="#9d1246" >        <button            androID:ID="@+ID/button_backfromreg"            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:layout_marginBottom="5dp"            androID:layout_marginleft="20dp"            androID:layout_margintop="10dp"            androID:background="@drawable/backbtn"            androID:visibility="visible" />    </linearLayout></linearLayout>

footer.xml

<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_wIDth="match_parent"    androID:layout_height="wrap_content"    androID:orIEntation="vertical" >    <linearLayout        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:background="#9d1246" >    </linearLayout></linearLayout>

我在mainlayout中包含了上面两个布局,如图所示

<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    androID:background="#eaedf2"    androID:orIEntation="vertical" >    <include        androID:layout_weight="1"        layout="@layout/header" />    <linearLayout        androID:layout_wIDth="match_parent"        androID:layout_height="0dp"        androID:layout_margin="30dp"        androID:layout_weight="1"        androID:orIEntation="vertical" >        <EditText            androID:ID="@+ID/editText1"            androID:layout_wIDth="match_parent"            androID:layout_height="wrap_content"            androID:editable="false"            androID:ems="10"            androID:hint="Country"            androID:textcolor="#655e5e"            androID:textSize="15sp" >            <requestFocus />        </EditText>        <EditText            androID:ID="@+ID/editText2"            androID:layout_wIDth="match_parent"            androID:layout_height="wrap_content"            androID:editable="false"            androID:ems="10"            androID:hint="State"            androID:textcolor="#655e5e"            androID:textSize="15sp" />        <EditText            androID:ID="@+ID/editText3"            androID:layout_wIDth="match_parent"            androID:layout_height="wrap_content"            androID:editable="false"            androID:ems="10"            androID:hint="Place Keyword"            androID:textcolor="#655e5e"            androID:textSize="15sp" />    </linearLayout>    <include        androID:layout_height="0dp"        androID:layout_weight="1"        layout="@layout/footer" /></linearLayout>

我的问题是,使用上面的布局我看不到页脚.有人请帮助我.
提前致谢.

解决方法 将包含的布局保留在容器中,并仅将权重属性设置为该容器.

这是您更新的布局

<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    androID:background="#eaedf2"    androID:orIEntation="vertical" >    <linearLayout        androID:layout_wIDth="match_parent"        androID:layout_height="0dp"        androID:layout_weight="1" >        <include            androID:layout_height="match_parent"            androID:layout_wIDth="match_parent"            layout="@layout/header" />    </linearLayout>    <linearLayout        androID:layout_wIDth="match_parent"        androID:layout_height="0dp"        androID:layout_margin="30dp"        androID:layout_weight="1"        androID:orIEntation="vertical" >        <EditText            androID:ID="@+ID/editText1"            androID:layout_wIDth="match_parent"            androID:layout_height="wrap_content"            androID:editable="false"            androID:ems="10"            androID:hint="Country"            androID:textcolor="#655e5e"            androID:textSize="15sp" >            <requestFocus />        </EditText>        <EditText            androID:ID="@+ID/editText2"            androID:layout_wIDth="match_parent"            androID:layout_height="wrap_content"            androID:editable="false"            androID:ems="10"            androID:hint="State"            androID:textcolor="#655e5e"            androID:textSize="15sp" />        <EditText            androID:ID="@+ID/editText3"            androID:layout_wIDth="match_parent"            androID:layout_height="wrap_content"            androID:editable="false"            androID:ems="10"            androID:hint="Place Keyword"            androID:textcolor="#655e5e"            androID:textSize="15sp" />    </linearLayout>    <linearLayout        androID:layout_wIDth="match_parent"        androID:layout_height="0dp"        androID:layout_weight="1" >        <include            androID:layout_height="match_parent"            androID:layout_wIDth="match_parent"            layout="@layout/footer" />    </linearLayout></linearLayout>
总结

以上是内存溢出为你收集整理的android – 如何为包含的布局设置权重?全部内容,希望文章能够帮你解决android – 如何为包含的布局设置权重?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1137282.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存