Syed Sehu Mujammil A
Syed Sehu Mujammil A

Reputation: 875

Android relative layout doesn't scroll

I have a relative layout in my xml file inside which I have another relative layout which has all my content. My Inner relative layout is loaded with content that comes from my database.

Also I have a edittext and button at bottom for adding comments.

Now the problem is that my inner relative layout doesn't scroll when the content is more but all the contents get hidden inside the bottom edit text and button.

Here is my xml.

<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="wrap_content"
        android:background="@color/BG"
        android:paddingTop="10dp" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:background="#FFFFFF"
        android:paddingLeft="15dp"
        android:paddingRight="15dp"
        android:paddingBottom="15dp"
        android:scrollbars="vertical" >

        <TextView
            android:id="@+id/discTitle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:layout_marginTop="20dp"
            android:text="Title"
            android:textColor="#77d3f1"
            android:textSize="18sp" />

        <TextView
            android:id="@+id/discCategory"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignRight="@+id/discTitle"
            android:layout_below="@+id/discTitle"
            android:layout_marginTop="20dp"
            android:text="Category"
            android:textColor="#77d3f1"
            android:textSize="14sp" />

        <TextView
            android:id="@+id/discDescription"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignRight="@+id/discCategory"
            android:layout_below="@+id/discCategory"
            android:layout_marginTop="20dp"
            android:text="Decsription"
            android:textColor="#908484"
            android:textSize="16sp" />

        <TextView
            android:id="@+id/discTime"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignRight="@+id/discDescription"
            android:layout_below="@+id/discDescription"
            android:layout_marginTop="20dp"
            android:text="yyyy mm dd hh:mm:ss"
            android:textSize="10sp" />
    </RelativeLayout>

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_marginRight="60dp"
        android:background="@drawable/commentbg"
        android:ems="10"
        android:hint="Type a comment..."
        android:inputType="textMultiLine"
        android:minHeight="40dp"
        android:paddingLeft="10dp"
        android:textStyle="italic" >

        <requestFocus />
    </EditText>

    <Button
        android:id="@+id/button1"
        android:layout_width="61dp"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:background="@drawable/commentbg"
        android:minHeight="40dp"
        android:text="Send" />

</RelativeLayout>

Now I want the inner relative layout’s height to occupy the whole screen and has to be scrollable when content is more.Have a look at the image below.

Thanks in advance.Layout View

Upvotes: 1

Views: 902

Answers (2)

Ahmed Khamis
Ahmed Khamis

Reputation: 83

Wrap it in ScrollView

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/scroll_view_layout">

    <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:background="#FFFFFF"
    android:paddingLeft="15dp"
    android:paddingRight="15dp"
    android:paddingBottom="15dp"
    android:scrollbars="vertical" >

    <TextView
        android:id="@+id/discTitle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_marginTop="20dp"
        android:text="Title"
        android:textColor="#77d3f1"
        android:textSize="18sp" />

    <TextView
        android:id="@+id/discCategory"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignRight="@+id/discTitle"
        android:layout_below="@+id/discTitle"
        android:layout_marginTop="20dp"
        android:text="Category"
        android:textColor="#77d3f1"
        android:textSize="14sp" />

    <TextView
        android:id="@+id/discDescription"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignRight="@+id/discCategory"
        android:layout_below="@+id/discCategory"
        android:layout_marginTop="20dp"
        android:text="Decsription"
        android:textColor="#908484"
        android:textSize="16sp" />

    <TextView
        android:id="@+id/discTime"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignRight="@+id/discDescription"
        android:layout_below="@+id/discDescription"
        android:layout_marginTop="20dp"
        android:text="yyyy mm dd hh:mm:ss"
        android:textSize="10sp" />
</RelativeLayout>

<EditText
    android:id="@+id/editText1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_marginRight="60dp"
    android:background="@drawable/commentbg"
    android:ems="10"
    android:hint="Type a comment..."
    android:inputType="textMultiLine"
    android:minHeight="40dp"
    android:paddingLeft="10dp"
    android:textStyle="italic" >

    <requestFocus />
</EditText>

<Button
    android:id="@+id/button1"
    android:layout_width="61dp"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:background="@drawable/commentbg"
    android:minHeight="40dp"
    android:text="Send" />

 </RelativeLayout>
</ScrollView>

Upvotes: 1

Jure
Jure

Reputation: 799

To scroll content you need to add ScrollView. ScrollView will be parent of the layout that you want to scroll. http://developer.android.com/reference/android/widget/ScrollView.html

Upvotes: 0

Related Questions