我有ScrollView的活动,包括一些内容,还有按钮。我想做我的按钮(@ + id / buttonSubmit)总是在屏幕的底部可见,独立滚动内容。有什么想法吗?
<?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:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/cyan50">
<LinearLayout xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="@dimen/activity_vertical_margin"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
>
// scroll content here
<Button
android:id="@+id/buttonSubmit"
style="@style/ButtonLight"
android:layout_gravity="center"
android:layout_marginTop="@dimen/default_medium_margin"
android:text="@string/submit_changes"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
答案 0 :(得分:0)
将根布局更改为FrameLayout,并将按钮设置为与滚动视图相同的级别,如果要确保它位于底部,请添加android:layout_gravity="bottom|right"
。 XML应该是这样的:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/cyan50">
<LinearLayout xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="@dimen/activity_vertical_margin"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context="com.brut.truckers.ui.activity.ProfileActivity">
<LinearLayout style="@style/LayoutTitle">
<TextView
style="@style/TextViewDefault"
android:layout_weight="1"
android:text="@string/trucker_name" />
</LinearLayout>
<EditText
android:id="@+id/editTextTruckerName"
style="@style/EditTextDefault"
android:layout_marginTop="@dimen/default_small_margin"
android:hint="@string/tap_to_edit" />
<LinearLayout
style="@style/LayoutTitle"
android:layout_marginTop="@dimen/default_big_margin">
<TextView
style="@style/TextViewDefault"
android:layout_weight="1"
android:text="@string/trucking_company" />
</LinearLayout>
<EditText
android:id="@+id/editTextTruckerCompany"
style="@style/EditTextDefault"
android:layout_marginTop="@dimen/default_small_margin"
android:hint="@string/tap_to_edit" />
<LinearLayout
style="@style/LayoutTitle"
android:layout_marginTop="@dimen/default_big_margin">
<TextView
style="@style/TextViewDefault"
android:layout_weight="1"
android:text="@string/tax_jurisdiction" />
</LinearLayout>
<EditText
android:id="@+id/editTextTaxJurisdiction"
style="@style/EditTextDefault"
android:layout_marginTop="@dimen/default_small_margin"
android:hint="@string/tap_to_edit" />
<LinearLayout
style="@style/LayoutTitle"
android:layout_marginTop="@dimen/default_big_margin">
<TextView
style="@style/TextViewDefault"
android:layout_weight="1"
android:text="@string/tax_registration" />
</LinearLayout>
<EditText
android:id="@+id/editTextTaxRegistration"
style="@style/EditTextDefault"
android:layout_marginTop="@dimen/default_small_margin"
android:hint="@string/tap_to_edit" />
<LinearLayout
style="@style/LayoutTitle"
android:layout_marginTop="@dimen/default_big_margin">
<TextView
style="@style/TextViewDefault"
android:layout_weight="1"
android:text="@string/driver_license_no" />
</LinearLayout>
<EditText
android:id="@+id/editTextDriverLicenseNo"
style="@style/EditTextDefault"
android:layout_marginTop="@dimen/default_small_margin"
android:hint="@string/tap_to_edit" />
</LinearLayout>
</ScrollView>
<Button
android:id="@+id/buttonSubmit"
style="@style/ButtonLight"
android:layout_gravity="bottom|right"
android:layout_marginTop="@dimen/default_medium_margin"
android:text="@string/submit_changes"/>
</FrameLayout >
答案 1 :(得分:0)
您可以使用例如一个RelativeLayout或一个FrameLayout来做这个
答案 2 :(得分:0)
LinearLayout
分配属性android:orientation="vertical"
ScrollView
分配属性android:layout_gravity="fill"
Button
应移出内部LinearLayout
和ScrollView
,并位于最外ScrollView
结束标记之前的LinearLayout
之后Button
分配属性android:layout_gravity="bottom"