gpt4 book ai didi

android - 在android中使用include布局时布局相互重叠

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:11:11 26 4
gpt4 key购买 nike

我有 3 个布局,main.xml、layout1.xml、layout2.xml。

layout1.xml 有大约 10 个文本字段,layout2.xml 有 4 个按钮

在 main.xml 中,我将其他 2 个布局称为

<include layout="@layout/data_layout"/>     
<include layout="@layout/button_layout"
android:layout_alignBottom="@layout/data_layout" />

现在我的问题是 layout1.xml 和 layout2.xml 相互重叠。但是我需要 layout2.xml 必须从 layout1.xml 的底部开始

对此有什么想法吗?

Main_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
android:id="@+id/nieTxtState"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:padding="@dimen/padding_medium"
android:text="@string/state"
android:textSize="14dp" />

<TextView
android:id="@+id/nieTxtTNState"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/nieTxtState"
android:padding="@dimen/padding_medium"
android:text="@string/tnState"
android:textSize="14dp" />

<include
layout="@layout/data_layout"/>
<include
layout="@layout/button_layout"
android:layout_alignBottom="@layout/data_layout" />

</RelativeLayout>

数据布局.xml

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

<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/light_blue"
android:orientation="vertical"
android:scrollbars="vertical" >

<TextView
android:id="@+id/nieTxtState"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:padding="@dimen/padding_medium"
android:text="@string/state"
android:textSize="14dp" />

<TextView
android:id="@+id/nieTxtTNState"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/nieTxtState"
android:padding="@dimen/padding_medium"
android:text="@string/tnState"
android:textSize="14dp" />

<TextView
android:id="@+id/txtViewDistrict"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/nieTxtTNState"
android:layout_marginLeft="5dp"
android:text="@string/district"
android:textColor="@color/black" />

<Spinner
android:id="@+id/spnDistrict"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txtViewDistrict"
android:layout_marginLeft="2dp" />

<TextView
android:id="@+id/txtViewHSS"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/spnDistrict"
android:layout_marginLeft="5dp"
android:text="@string/hssSite"
android:textColor="@color/black" />

<Spinner
android:id="@+id/spnHSS"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txtViewHSS"
android:layout_marginLeft="2dp" />

<TextView
android:id="@+id/txtViewAge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/spnHSS"
android:layout_marginLeft="5dp"
android:text="@string/age"
android:textColor="@color/black" />

<EditText
android:id="@+id/edtTxtAge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txtViewAge"
android:layout_marginLeft="2dp"
android:hint="@string/hintAge"
android:inputType="number"
android:maxLength="2"
android:textSize="14dp" />

<TextView
android:id="@+id/txtViewLiteracy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/edtTxtAge"
android:layout_marginLeft="5dp"
android:text="@string/literacyStatus"
android:textColor="@color/black" />

<Spinner
android:id="@+id/spnLiteracy"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txtViewLiteracy"
android:layout_marginLeft="2dp" />

<TextView
android:id="@+id/txtViewPregnancy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/spnLiteracy"
android:layout_marginLeft="5dp"
android:text="@string/currentPregnancy"
android:textColor="@color/black" />

<Spinner
android:id="@+id/spnPregnancy"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txtViewPregnancy"
android:layout_marginLeft="2dp" />

<TextView
android:id="@+id/txtViewReferralSource"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/spnPregnancy"
android:layout_marginLeft="5dp"
android:text="@string/referralSource"
android:textColor="@color/black" />

<Spinner
android:id="@+id/spnReferralSource"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txtViewReferralSource"
android:layout_marginLeft="2dp" />

<TextView
android:id="@+id/txtViewResidence"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/spnReferralSource"
android:layout_marginLeft="5dp"
android:text="@string/residecnePlace"
android:textColor="@color/black" />

<Spinner
android:id="@+id/spnResidence"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txtViewResidence"
android:layout_marginLeft="2dp" />

<TextView
android:id="@+id/txtViewDurationOfStay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/spnResidence"
android:layout_marginLeft="5dp"
android:text="@string/DurationOfStay"
android:textColor="@color/black" />

<EditText
android:id="@+id/edtTxtDurationOfYear"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_below="@id/txtViewDurationOfStay"
android:layout_marginLeft="2dp"
android:layout_marginRight="20dp"
android:hint="@string/hintYear"
android:inputType="number"
android:maxLength="4"
android:textSize="14dp" />

<EditText
android:id="@+id/edtTxtDurationOfMonth"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_below="@id/txtViewDurationOfStay"
android:layout_toRightOf="@id/edtTxtDurationOfYear"
android:hint="@string/hintMonth"
android:inputType="number"
android:maxLength="2"
android:textSize="14dp" />

<TextView
android:id="@+id/txtViewRespOccupation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/edtTxtDurationOfYear"
android:layout_marginLeft="5dp"
android:text="@string/respondentOccupation"
android:textColor="@color/black" />

<Spinner
android:id="@+id/spnRespOccupation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txtViewRespOccupation"
android:layout_marginLeft="2dp" />

<TextView
android:id="@+id/txtViewSpouseOccupation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/spnRespOccupation"
android:layout_marginLeft="5dp"
android:text="@string/spouseOccupation"
android:textColor="@color/black" />

<Spinner
android:id="@+id/spnSpouseOccupation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txtViewSpouseOccupation"
android:layout_marginLeft="2dp" />

<TextView
android:id="@+id/txtViewSpouseResidesAwayFromWife"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/spnSpouseOccupation"
android:layout_marginLeft="5dp"
android:text="@string/spouseResidesAwayFromWife"
android:textColor="@color/black" />

<Spinner
android:id="@+id/spnSpouseResidesAwayFromWife"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txtViewSpouseResidesAwayFromWife"
android:layout_marginLeft="2dp" />
</RelativeLayout>

按钮布局.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="bottom">

<Button
android:id="@+id/ancSaveBtn"
android:layout_width="80dp"
android:layout_height="35dp"
android:layout_alignParentLeft="true"
android:layout_marginTop="15dp"
android:text="@string/upload"
android:textSize="14dp" />

<Button
android:id="@+id/ancAddNewBtn"
android:layout_width="80dp"
android:layout_height="35dp"
android:layout_marginTop="15dp"
android:layout_toRightOf="@id/ancSaveBtn"
android:text="@string/addNew"
android:textSize="14dp" />

<Button
android:id="@+id/ancClearBtn"
android:layout_width="80dp"
android:layout_height="35dp"
android:layout_marginTop="15dp"
android:layout_toRightOf="@id/ancAddNewBtn"
android:text="@string/clear"
android:textSize="14dp" />

<Button
android:id="@+id/ancExitBtn"
android:layout_width="80dp"
android:layout_height="35dp"
android:layout_marginTop="15dp"
android:layout_toRightOf="@id/ancClearBtn"
android:text="@string/exit"
android:textSize="14dp" />

</RelativeLayout>

最佳答案

我必须四处走走才能获得正确的布局。如果这不是您想要的,请随时在此处发布您想要存档的屏幕截图

主.xml

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

<include
android:id="@+id/layout_content_1"
android:layout_alignParentTop="true"
android:layout_below="@+id/layout_content_2"
layout="@layout/top_layout" />

<include
android:id="@+id/layout_content_2"
android:layout_above="@+id/layout_content_1"
layout="@layout/data_layout" />

<include
android:id="@+id/layout_content_3"
layout="@layout/button_layout" />

</RelativeLayout>

按钮布局.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom" >

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >

<Button
android:id="@+id/ancSaveBtn"
android:layout_width="80dp"
android:layout_height="35dp"
android:layout_marginTop="15dp"
android:text="upload"
android:textSize="14dp" />

<Button
android:id="@+id/ancAddNewBtn"
android:layout_width="80dp"
android:layout_height="35dp"
android:layout_marginTop="15dp"
android:text="new"
android:textSize="14dp" />

<Button
android:id="@+id/ancClearBtn"
android:layout_width="80dp"
android:layout_height="35dp"
android:layout_marginTop="15dp"
android:text="clear"
android:textSize="14dp" />

<Button
android:id="@+id/ancExitBtn"
android:layout_width="80dp"
android:layout_height="35dp"
android:layout_marginTop="15dp"
android:text="edit"
android:textSize="14dp" />
</LinearLayout>

</RelativeLayout>

数据布局.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="36dp"
android:layout_marginTop="36dp"
android:scrollbars="vertical" >

<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="vertical"
android:scrollbars="vertical" >

<TextView
android:id="@+id/nieTxtState"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:padding="@dimen/padding_medium"
android:text="state"
android:textSize="14dp" />

<TextView
android:id="@+id/nieTxtTNState"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/nieTxtState"
android:padding="@dimen/padding_medium"
android:text="tnState"
android:textSize="14dp" />

<TextView
android:id="@+id/txtViewDistrict"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/nieTxtTNState"
android:layout_marginLeft="5dp"
android:text="district"
android:textColor="@color/black" />

<Spinner
android:id="@+id/spnDistrict"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txtViewDistrict"
android:layout_marginLeft="2dp" />

<TextView
android:id="@+id/txtViewHSS"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/spnDistrict"
android:layout_marginLeft="5dp"
android:text="hssSite"
android:textColor="@color/black" />

<Spinner
android:id="@+id/spnHSS"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txtViewHSS"
android:layout_marginLeft="2dp" />

<TextView
android:id="@+id/txtViewAge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/spnHSS"
android:layout_marginLeft="5dp"
android:text="age"
android:textColor="@color/black" />

<EditText
android:id="@+id/edtTxtAge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txtViewAge"
android:layout_marginLeft="2dp"
android:hint="hintAge"
android:inputType="number"
android:maxLength="2"
android:textSize="14dp" />

<TextView
android:id="@+id/txtViewLiteracy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/edtTxtAge"
android:layout_marginLeft="5dp"
android:text="literacyStatus"
android:textColor="@color/black" />

<Spinner
android:id="@+id/spnLiteracy"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txtViewLiteracy"
android:layout_marginLeft="2dp" />

<TextView
android:id="@+id/txtViewPregnancy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/spnLiteracy"
android:layout_marginLeft="5dp"
android:text="currentPregnancy"
android:textColor="@color/black" />

<Spinner
android:id="@+id/spnPregnancy"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txtViewPregnancy"
android:layout_marginLeft="2dp" />

<TextView
android:id="@+id/txtViewReferralSource"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/spnPregnancy"
android:layout_marginLeft="5dp"
android:text="referralSource"
android:textColor="@color/black" />

<Spinner
android:id="@+id/spnReferralSource"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txtViewReferralSource"
android:layout_marginLeft="2dp" />

<TextView
android:id="@+id/txtViewResidence"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/spnReferralSource"
android:layout_marginLeft="5dp"
android:text="residecnePlace"
android:textColor="@color/black" />

<Spinner
android:id="@+id/spnResidence"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txtViewResidence"
android:layout_marginLeft="2dp" />

<TextView
android:id="@+id/txtViewDurationOfStay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/spnResidence"
android:layout_marginLeft="5dp"
android:text="DurationOfStay"
android:textColor="@color/black" />

<EditText
android:id="@+id/edtTxtDurationOfYear"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_below="@id/txtViewDurationOfStay"
android:layout_marginLeft="2dp"
android:layout_marginRight="20dp"
android:hint="hintYear"
android:inputType="number"
android:maxLength="4"
android:textSize="14dp" />

<EditText
android:id="@+id/edtTxtDurationOfMonth"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_below="@id/txtViewDurationOfStay"
android:layout_toRightOf="@id/edtTxtDurationOfYear"
android:hint="hintMonth"
android:inputType="number"
android:maxLength="2"
android:textSize="14dp" />

<TextView
android:id="@+id/txtViewRespOccupation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/edtTxtDurationOfYear"
android:layout_marginLeft="5dp"
android:text="respondentOccupation"
android:textColor="@color/black" />

<Spinner
android:id="@+id/spnRespOccupation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txtViewRespOccupation"
android:layout_marginLeft="2dp" />

<TextView
android:id="@+id/txtViewSpouseOccupation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/spnRespOccupation"
android:layout_marginLeft="5dp"
android:text="spouseOccupation"
android:textColor="@color/black" />

<Spinner
android:id="@+id/spnSpouseOccupation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txtViewSpouseOccupation"
android:layout_marginLeft="2dp" />

<TextView
android:id="@+id/txtViewSpouseResidesAwayFromWife"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/spnSpouseOccupation"
android:layout_marginLeft="5dp"
android:text="spouseResidesAwayFromWife"
android:textColor="@color/black" />

<Spinner
android:id="@+id/spnSpouseResidesAwayFromWife"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txtViewSpouseResidesAwayFromWife"
android:layout_marginLeft="2dp" />
</RelativeLayout>
</ScrollView>

</RelativeLayout>

top_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_gravity="top"
android:orientation="vertical" >

<TextView
android:id="@+id/nieTxtState"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/padding_medium"
android:text="123434343434"
android:textSize="14dp" />

<TextView
android:id="@+id/nieTxtTNState"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/nieTxtState"
android:padding="@dimen/padding_medium"
android:text="1233434343"
android:textSize="14dp" />

</RelativeLayout>

关于android - 在android中使用include布局时布局相互重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15112217/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com