如何在片段中存在的相对布局中使用滚动视图?

How to use scroll view in relative layout which exist in fragment?

我卡住了如何在出现键盘时滚动布局?这是我的静态页面,但是当我的键盘出现时,我的滚动视图不是 working.i 无法给出滚动视图的硬代码高度。请帮助我..

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/settingLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/splash_bg" >

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
              android:layout_centerInParent="true" >

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                   >

                    <ImageView
                        android:id="@+id/tree_iv_userSettings"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerInParent="true"
                        android:background="@drawable/tree_transparent" />

                    <ImageView
                        android:id="@+id/image1"
                        android:layout_width="90dp"
                        android:layout_height="110dp"
                        android:layout_centerHorizontal="true"
                        android:layout_marginBottom="30dp"
                        android:src="@drawable/frame_large" />

                    <TextView
                        android:id="@+id/changepassword"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true"
                        android:layout_below="@+id/image1"
                        android:layout_marginLeft="20dp"
                        android:background="@android:color/transparent"
                        android:hint="CHANGE PASSWORD"
                        android:singleLine="true"
                        android:textAppearance="?android:attr/textAppearanceLarge"
                        android:textColor="@android:color/black"
                        android:textColorHint="@android:color/black" />


                    <EditText
                        android:id="@+id/editname"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true"
                        android:layout_below="@+id/changepassword"
                        android:layout_marginLeft="20dp"
                        android:layout_marginTop="15dp"
                        android:background="@android:color/transparent"
                        android:hint="EDIT NAME"
                        android:maxLength="20"
                        android:singleLine="true"
                        android:textAppearance="?android:attr/textAppearanceLarge"
                        android:textColorHint="@android:color/black" />

                    <EditText
                        android:id="@+id/editphoneno"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true"
                        android:layout_below="@+id/editname"
                        android:layout_marginLeft="20dp"
                        android:layout_marginTop="15dp"
                        android:background="@android:color/transparent"
                        android:hint="EDIT PHONE NUMBER"
                        android:maxLength="15"
                        android:numeric="integer"
                        android:singleLine="true"
                        android:textAppearance="?android:attr/textAppearanceLarge"
                        android:textColorHint="@android:color/black" />

                    <TextView
                        android:id="@+id/edittype"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true"
                        android:layout_below="@+id/editphoneno"
                        android:layout_marginLeft="20dp"
                        android:layout_marginTop="15dp"
                        android:background="@android:color/transparent"
                        android:singleLine="true"
                        android:text="EDIT TYPE"
                        android:textAppearance="?android:attr/textAppearanceLarge"
                        android:textColor="@android:color/black" />

                    <TextView
                        android:id="@+id/notification"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true"
                        android:layout_below="@+id/edittype"
                        android:layout_marginLeft="20dp"
                        android:layout_marginTop="15dp"
                        android:background="@android:color/transparent"
                        android:singleLine="true"
                        android:text="NOTIFICATION"
                        android:textAppearance="?android:attr/textAppearanceLarge"
                        android:textColor="@android:color/black" />

                    <Button
                        android:id="@+id/togNot"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_above="@+id/save"
                        android:layout_alignParentRight="true"
                        android:layout_marginRight="20dp"
                        android:background="@drawable/on_button" />

                    <TextView
                        android:id="@+id/save"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/notification"
                        android:layout_centerHorizontal="true"
                        android:layout_marginTop="30dp"
                        android:background="@android:color/transparent"
                        android:text="SAVE "
                        android:textAppearance="?android:attr/textAppearanceLarge"
                        android:textColor="@android:color/black"
                        android:textSize="40dp" />

                    <ProgressBar
                        android:id="@+id/progressBar1"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignBottom="@+id/image1"
                        android:layout_centerHorizontal="true"
                        android:layout_marginBottom="27dp" />
                </RelativeLayout>
        </ScrollView>




Please help me out.
suggestions apreciated
Thanks Kind Regards.

在您的清单活动中添加此代码

android:windowSoftInputMode="adjustPan|stateAlwaysVisible"

试试这个:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@drawable/splash_bg" >

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <ImageView
        android:id="@+id/tree_iv_userSettings"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:background="@drawable/tree_transparent" />

    <ImageView
        android:id="@+id/image1"
        android:layout_width="90dp"
        android:layout_height="110dp"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="30dp"
        android:src="@drawable/frame_large" />

    <TextView
        android:id="@+id/changepassword"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/image1"
        android:layout_marginLeft="20dp"
        android:background="@android:color/transparent"
        android:hint="CHANGE PASSWORD"
        android:singleLine="true"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="@android:color/black"
        android:textColorHint="@android:color/black" />

    <EditText
        android:id="@+id/editname"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/changepassword"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="15dp"
        android:background="@android:color/transparent"
        android:hint="EDIT NAME"
        android:maxLength="20"
        android:singleLine="true"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColorHint="@android:color/black" />

    <EditText
        android:id="@+id/editphoneno"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/editname"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="15dp"
        android:background="@android:color/transparent"
        android:hint="EDIT PHONE NUMBER"
        android:maxLength="15"
        android:numeric="integer"
        android:singleLine="true"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColorHint="@android:color/black" />

    <TextView
        android:id="@+id/edittype"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/editphoneno"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="15dp"
        android:background="@android:color/transparent"
        android:singleLine="true"
        android:text="EDIT TYPE"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="@android:color/black" />

    <TextView
        android:id="@+id/notification"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/edittype"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="15dp"
        android:background="@android:color/transparent"
        android:singleLine="true"
        android:text="NOTIFICATION"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="@android:color/black" />

    <Button
        android:id="@+id/togNot"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/save"
        android:layout_alignParentRight="true"
        android:layout_marginRight="20dp"
        android:background="@drawable/on_button" />

    <TextView
        android:id="@+id/save"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/notification"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="30dp"
        android:background="@android:color/transparent"
        android:text="SAVE "
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="@android:color/black"
        android:textSize="40dp" />

    <ProgressBar
        android:id="@+id/progressBar1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/image1"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="27dp" />
</RelativeLayout>

并将这段代码添加到您的清单项目中:

 <activity
        android:name="YourActivity"
        android:windowSoftInputMode="stateVisible|stateAlwaysVisible" >
    </activity>
this code useful for scrolling relative layout..

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
            >

        <RelativeLayout
            android:id="@+id/settingLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:background="@drawable/splash_bg" >

            <ImageView
                android:id="@+id/tree_iv_userSettings"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:background="@drawable/tree_transparent" />

            <ImageView
                android:id="@+id/image1"
                android:layout_width="90dp"
                android:layout_height="110dp"
                android:layout_centerHorizontal="true"
                android:layout_marginBottom="30dp"
                android:src="@drawable/frame_large" />

            <TextView
                android:id="@+id/changepassword"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_below="@+id/image1"
                android:layout_marginLeft="20dp"
                android:background="@android:color/transparent"
                android:hint="CHANGE PASSWORD"
                android:singleLine="true"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:textColor="@android:color/black"
                android:textColorHint="@android:color/black" />

            <EditText
                android:id="@+id/editname"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_below="@+id/changepassword"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="15dp"
                android:background="@android:color/transparent"
                android:hint="EDIT NAME"
                android:maxLength="20"
                android:singleLine="true"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:textColorHint="@android:color/black" />

            <EditText
                android:id="@+id/editphoneno"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_below="@+id/editname"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="15dp"
                android:background="@android:color/transparent"
                android:hint="EDIT PHONE NUMBER"
                android:maxLength="15"
                android:numeric="integer"
                android:singleLine="true"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:textColorHint="@android:color/black" />

            <TextView
                android:id="@+id/edittype"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_below="@+id/editphoneno"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="15dp"
                android:background="@android:color/transparent"
                android:singleLine="true"
                android:text="EDIT TYPE"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:textColor="@android:color/black" />

            <TextView
                android:id="@+id/notification"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_below="@+id/edittype"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="15dp"
                android:background="@android:color/transparent"
                android:singleLine="true"
                android:text="NOTIFICATION"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:textColor="@android:color/black" />

            <Button
                android:id="@+id/togNot"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_above="@+id/save"
                android:layout_alignParentRight="true"
                android:layout_marginRight="20dp"
                android:background="@drawable/on_button" />

            <TextView
                android:id="@+id/save"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/notification"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="30dp"
                android:background="@android:color/transparent"
                android:text="SAVE "
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:textColor="@android:color/black"
                android:textSize="40dp" />

            <ProgressBar
                android:id="@+id/progressBar1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignBottom="@+id/image1"
                android:layout_centerHorizontal="true"
                android:layout_marginBottom="27dp" />
        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/bottomRelay"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_margin="7.5dp"
            android:background="@android:color/transparent"
            android:visibility="gone" >

            <TextView
                android:id="@+id/Upload"
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:layout_marginLeft="30dp"
                android:layout_marginRight="30dp"
                android:background="#ededed"
                android:gravity="center"
                android:text="Upload Photo"
                android:textColor="#8F8F8F"
                android:textSize="20dp"
                android:textStyle="bold" />

            <ImageView
                android:id="@+id/border1"
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_below="@id/Upload"
                android:layout_marginLeft="30dp"
                android:layout_marginRight="30dp"
                android:background="#939393" />

            <TextView
                android:id="@+id/choose_existing"
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:layout_below="@+id/border1"
                android:layout_marginLeft="30dp"
                android:layout_marginRight="30dp"
                android:layout_marginTop="1dp"
                android:background="#ededed"
                android:gravity="center"
                android:text="Library"
                android:textColor="#007AFF"
                android:textSize="20dp"
                android:textStyle="bold" />

            <ImageView
                android:id="@+id/border2"
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_below="@id/choose_existing"
                android:layout_marginLeft="30dp"
                android:layout_marginRight="30dp"
                android:background="#939393" />

            <TextView
                android:id="@+id/Camera"
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:layout_below="@+id/border2"
                android:layout_marginLeft="30dp"
                android:layout_marginRight="30dp"
                android:layout_marginTop="1dp"
                android:background="#ededed"
                android:gravity="center"
                android:text="Camera"
                android:textColor="#007AFF"
                android:textSize="20dp"
                android:textStyle="bold" />

            <ImageView
                android:id="@+id/border3"
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_below="@id/Camera"
                android:layout_marginLeft="30dp"
                android:layout_marginRight="30dp"
                android:background="#939393" />

            <TextView
                android:id="@+id/cancel"
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:layout_below="@+id/border3"
                android:layout_marginLeft="30dp"
                android:layout_marginRight="30dp"
                android:layout_marginTop="20dp"
                android:background="#ededed"
                android:gravity="center"
                android:text="Cancel"
                android:textColor="#007AFF"
                android:textSize="20dp"
                android:textStyle="bold" />
        </RelativeLayout>
    </RelativeLayout>

</ScrollView>