ScrollView inside RelativeLayout

I need to make the scroll view in a relative layout.

When I added ScrollView, this was the result of http://postimg.org/image/6abxth299/ where the components occupy only half the screen and when this screen opens the default keyboard

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:scrollbars="vertical" >
    <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: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=".MainActivity"
        android:layout_centerHorizontal="true"
        android:id="@+id/data_entry_layout">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Post Title"
                android:id="@+id/post_title"
                android:layout_alignBaseline="@+id/post_title_input"
                android:layout_alignBottom="@+id/post_title_input"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:textSize="26px"/>

            <EditText
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:id="@+id/post_title_input"
                android:layout_alignParentRight="true"
                android:layout_alignParentEnd="true"
                android:layout_toRightOf="@+id/post_title"
                android:layout_toEndOf="@+id/post_title"
                android:inputType="textCapSentences"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Post Description"
                android:id="@+id/post_description"
                android:layout_below="@+id/post_title_input"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_marginTop="39dp"
                android:textSize="26px"/>

            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textMultiLine|textCapSentences"
                android:ems="10"
                android:id="@+id/editText"
                android:layout_marginTop="16dp"
                android:layout_below="@+id/post_description"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"/>

            <ImageButton
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/imageButton1"
                android:layout_below="@+id/editText"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:baselineAlignBottom="false"
                android:contextClickable="true"
                android:src="@drawable/image_button_icon"
                android:onClick="galleryIntent"/>

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Cancel"
                android:id="@+id/cancel"
                android:layout_alignParentBottom="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_below="@id/imageButton1"

               />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Submit"
                android:id="@+id/submit"
                android:layout_alignTop="@+id/cancel"
                android:layout_alignParentRight="true"
                android:layout_alignParentEnd="true"
                android:layout_below="@id/imageButton1"/>

    </RelativeLayout>
</ScrollView>
+4
source share
4 answers

Try adding below to your AndroidManifest in your action to remove the default keyboard.

android:windowSoftInputMode="stateAlwaysHidden|adjustResize"

android:layout_height="wrap_content" scrollview, LinearLayout .

0

dirsct , , . , , imageButton.

+1

I think ScrollView is not working inside Relativelayout. Better to use LinearLayout.

0
source

Try this one ...

<?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:id="@+id/data_entry_layout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_centerHorizontal="true"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin">
        <RelativeLayout
            android:id="@+id/Rel12345"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

        <TextView
            android:id="@+id/post_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/post_title_input"
            android:layout_alignBottom="@+id/post_title_input"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:text="Post Title"
            android:textSize="26px" />

        <EditText
            android:id="@+id/post_title_input"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_toEndOf="@+id/post_title"
            android:layout_toRightOf="@+id/post_title"
            android:inputType="textCapSentences" />

        <TextView
            android:id="@+id/post_description"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/post_title_input"
            android:layout_marginTop="39dp"
            android:text="Post Description"
            android:textSize="26px" />

        <EditText
            android:id="@+id/editText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/post_description"
            android:layout_marginTop="16dp"
            android:ems="10"
            android:inputType="textMultiLine|textCapSentences" />

        <ImageButton
            android:id="@+id/imageButton1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/editText"
            android:baselineAlignBottom="false"
            android:contextClickable="true"
            android:onClick="galleryIntent"
            />
        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/Rel1234"
            android:layout_below="@id/Rel12345"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true">

            <Button
                android:id="@+id/cancel"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:text="Cancel"/>

            <Button
                android:id="@+id/submit"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:layout_alignTop="@+id/cancel"
                android:text="Submit" />
        </RelativeLayout>
    </RelativeLayout>
</ScrollView>

and try adding below in AndroidManifes to remove the default keyboard.

android:windowSoftInputMode="stateAlwaysHidden|adjustResize"
0
source

All Articles