繁体   English   中英

在布局和滚动视图底部添加按钮

[英]Add button at the bottom of layout and scrollview

我有一个包含 2 个 EditText 和 3 个按钮的活动布局。 我想将滚动视图应用于整个布局。 最后一个按钮应该总是在布局的底部; 它也应该与其他 EditText 和按钮属于同一个滚动视图。

这是一个视觉描述:

所需的输出

我所做的是不允许第三个按钮位于布局的底部。 我们还必须记住,屏幕尺寸不同,因此第三个按钮的位置应该足够动态,可以位于任何屏幕尺寸的底部,并且也属于滚动视图。

我的布局代码:

<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>

请给我建议一种方法来实现相同的目标。

试试这个代码..

只需使用它而不是您的“ScrollView”代码..

<ScrollView
        android:id="@+id/scrollView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        android:scrollbars = "vertical"
        android:scrollbarStyle="insideInset" >       

 // continue your code

</ScrollView>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM