scrollView with Button at Bottom of screen

余生颓废 提交于 2019-12-23 06:23:20

问题


i have to use a scroll view for the form data and a button that should be at a bottom of the screen. i have achived it . but the problem is whenever the EditText gets focused and keyboard is opened the button does not stays at the bottom of the screen it comes just above the android key board . i want it to be there at bottom even when the keyboard is opend or not.

i have tried the android:fillViewport="true" with scroll view but it does not gives proper output.

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

            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/lout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">


            <ScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fillViewport="true">

                <LinearLayout
                    android:id="@+id/fout"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:paddingBottom="16dp"
                    android:paddingTop="10dp">

                    <ImageView
                        android:id="@+id/fimg"
                        android:layout_width="match_parent"
                        android:layout_height="250dp"
                        android:src="@drawable/addimg" />

                    <android.support.design.widget.TextInputLayout
                        android:id="@+id/vsubcusine"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:paddingBottom="10dp"
                        android:paddingLeft="5dp"
                        android:paddingRight="5dp"
                        android:paddingTop="10dp"
            >

                        <EditText
                            android:id="@+id/add_food_title"
                            style="@style/textbox"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:hint="Title for Food"
                            android:inputType="text"

                            />
                    </android.support.design.widget.TextInputLayout>

                    <android.support.design.widget.TextInputLayout
                        android:id="@+id/vcusine"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:hint="cusine"
                        android:paddingBottom="10dp"
                        android:paddingLeft="10dp"
                        android:paddingRight="10dp"
                        android:paddingTop="0dp">

                        <Spinner
                            android:id="@+id/cusine"
                            style="@style/textbox"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:background="#fff"
                            android:padding="10dp" />
                    </android.support.design.widget.TextInputLayout>

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal"
                        android:paddingBottom="10dp"
                        android:paddingLeft="10dp"
                        android:paddingRight="10dp"
                        android:paddingTop="10dp">


                        <RadioGroup
                            android:id="@+id/isveg"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:orientation="horizontal"
                            android:paddingLeft="20dp">

                            <RadioButton
                                android:id="@+id/veg"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:layout_weight="2"
                                android:text="Veg" />

                            <RadioButton
                                android:id="@+id/nonveg"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:layout_weight="2"

                                android:text="Non-Veg" />

                        </RadioGroup>
                    </LinearLayout>

                    <android.support.design.widget.TextInputLayout
                        android:id="@+id/vfprice"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:paddingBottom="0dp"
                        android:paddingLeft="10dp"
                        android:paddingRight="10dp"
                        android:paddingTop="0dp"
                        >

                        <EditText
                            android:id="@+id/fprice"
                            style="@style/textbox"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:hint="price"
                            android:inputType="number" />


                    </android.support.design.widget.TextInputLayout>
                </LinearLayout>
            </ScrollView>


            <LinearLayout
                android:id="@+id/t"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:gravity="center"
                android:orientation="horizontal"
                android:weightSum="2">

                <Button
                    android:id="@+id/foodadd"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_margin="10dp"
                    android:layout_weight="1"
                    android:background="@drawable/button"
                    android:text="ADD FOOD"
                    android:textColor="#FFF"
                    android:textStyle="bold" />
            </LinearLayout>

        </RelativeLayout>

回答1:


In manifest, Just Add android:windowSoftInputMode="adjustPan" to your corresponding activity tag:

     <activity
        android:name=".YourActivity"
        android:windowSoftInputMode="adjustPan">

Output:

Hope this helps.



来源:https://stackoverflow.com/questions/42910212/scrollview-with-button-at-bottom-of-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!