【发布时间】:2014-12-16 06:37:37
【问题描述】:
我有一个包含 2 个 EditText 和 3 个按钮的活动布局。我想将滚动视图应用于整个布局。最后一个按钮应始终位于布局的底部;它也应该与其他 EditText 和 Buttons 属于同一个滚动视图。
这是一个视觉描述:
我所做的是不允许第三个按钮位于布局的底部。我们还必须记住屏幕尺寸不同,因此第三个按钮的位置应该足够动态,可以位于任何屏幕尺寸的底部,并且也属于滚动视图。
我的布局代码:
<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:layout_alignParentBottom="false"
android:layout_centerHorizontal="true"
android:layout_centerInParent="false"
android:layout_centerVertical="true"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".AddDetails" >
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:id="@+id/first_layout">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="92dp"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical" >
<EditText
android:id="@+id/firstNameEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="First Name"
android:lines="1"
android:singleLine="true"
android:textSize="24sp" >
</EditText>
<EditText
android:id="@+id/lastNameEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Last Name"
android:lines="1"
android:singleLine="true"
android:textSize="24sp" />
<EditText
android:id="@+id/emailEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Email address"
android:inputType="textEmailAddress"
android:lines="1"
android:singleLine="true"
android:textSize="24sp"
android:visibility="gone" />
<Button
android:id="@+id/locationEdit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:lines="1"
android:singleLine="true"
android:text="Country"
android:textColor="#FFFFFF"
android:textSize="20sp" />
<Button
android:id="@+id/dateOfBirthEdit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Date of birth"
android:textColor="#FFFFFF"
android:textSize="20sp" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/first_layout">
<Button
android:id="@+id/nextScreenBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/next_button_selector"
android:text="Next"
android:textColor="#FFFFFF"
android:textSize="20sp" />
</RelativeLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
请给我一个实现相同目标的方法。
【问题讨论】:
-
将
nextScreenBtn代码保留在滚动布局之外。所以按钮将始终位于屏幕底部。 -
@Prag'sshi 做不到,应该在滚动视图里面,这是整个故事中最棘手的部分!
-
与答案无关,但你不应该经常使用RelativeLayout。
标签: java android xml android-layout