【发布时间】:2016-04-15 19:26:02
【问题描述】:
主要的问题是当包含FrameLayout、scrollView和linearLayout时如何设计布局不相互重叠?
我很难用下面的 xml 代码实现我想要的界面! 我想要的是:
有一个 FrameLayout 作为根来放置
a ScrollView containing other linear layout, textviews , ...
a LinearLayout which contains 4 Buttons
现在的输出是这样的,可以防止点击按钮。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="polimi.aap.yas.personalhealthrecord.EditPersonal">
<FrameLayout
android:id="@+id/flContent_ep"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/linearLayout2"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_gravity="bottom">
<Button
android:layout_width="wrap_content"
android:layout_height="70dp"
android:background="@mipmap/generalbtnimg"
android:id="@+id/btnClearAll_editP"
android:layout_weight="1"
android:text="Clear All"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="70dp"
android:background="@mipmap/generalbtnimg"
android:id="@+id/btnSubmit_editP"
android:layout_weight="1"
android:text="Submit" />
<Button
android:layout_width="wrap_content"
android:layout_height="70dp"
android:background="@mipmap/generalbtnimg"
android:id="@+id/btnChangePass_editP"
android:layout_weight="1"
android:text="Password" />
<Button
android:layout_width="wrap_content"
android:layout_height="70dp"
android:background="@mipmap/generalbtnimg"
android:id="@+id/btnReviewInfo_editP"
android:layout_weight="1"
android:text="Summary" />
</LinearLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/scrollView"
android:scrollIndicators="right"
android:layout_above="@id/linearLayout2"
>
<LinearLayout
android:id="@+id/linearLayout_Sc"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:padding="10dp" >
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/txtFirstName_editP"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:hint="First Name ..."/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="date"
android:ems="10"
android:id="@+id/txtDateOfBirth_editP"
android:hint="Birth Date ..."
android:layout_below="@+id/txtLastName_editP"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnCal_editP"
android:background="@mipmap/calendaricon"
android:layout_below="@+id/txtLastName_editP"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_gravity="right" />
</LinearLayout>
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/radioGroupGender_editP"
android:layout_below="@+id/btnCal_editP"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:onClick="showDatePickerDialog"
android:clickable="true">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female"
android:id="@+id/rbtn_female"
android:checked="false"
android:layout_weight="1"
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male"
android:id="@+id/rbtn_male"
android:checked="false"
android:layout_weight="1"
/>
</RadioGroup>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/txtAddress1_editP"
android:hint="Address Line1..."
android:layout_below="@+id/radioGroupGender_editP"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
.
.
.
</LinearLayout>
</ScrollView>
</FrameLayout>
</RelativeLayout>
请你看看上面的代码,告诉我为什么结果是这样的?
【问题讨论】:
-
你必须把你的按钮从底部放在哪里?
-
@harshadpansuriya 我希望它们位于底部的线性布局中。就像您在屏幕截图中看到的一样,但它似乎位于 scrollView 后面。
-
在下面试试我的答案。
标签: xml android-layout android-studio android-linearlayout android-scrollview