Make layout scrollable

75 views Asked by At

i have this layout which is not scrollable

i tried a lot of solutions and read a lot of questions and answers and nothing worked with me

<LinearLayout 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="com.twaa9l.chates.MyProfile"
    android:weightSum="2"
    android:scrollbars="horizontal"
    android:orientation="vertical" >


    <RelativeLayout
        android:layout_weight="1.5"   
        android:layout_width="match_parent"
        android:layout_height="0dp">

            <ImageView
                android:id="@+id/profilePicture" 
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/balloon"
                android:scaleType="fitXY"
                android:contentDescription="Main Image"
                android:padding="1dp"/>

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:contentDescription="image"
                android:clickable="true"
                android:padding="4dp"
                android:layout_margin="8dp"
                android:scaleType="fitXY"
                android:background="@drawable/edit_states"
                android:src="@drawable/ic_action_edit"
                android:layout_alignParentBottom="true"
                android:layout_alignParentRight="true"/>
    </RelativeLayout>

<!-- Full Name -->
    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="0.25"
        android:layout_marginTop="@dimen/activity_vertical_margin">

       <EditText 
            android:id="@+id/fullName"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/textview_border"
            android:hint="Enter sample text..."
            android:paddingTop="6dp"
            android:paddingBottom="8dp"
            android:paddingLeft="6dp"
            android:textSize="18sp"
            android:gravity="center_vertical"/>

       <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:contentDescription="Edit image icon"
            android:clickable="true"
            android:padding="4dp"
            android:layout_margin="8dp"
            android:scaleType="fitXY"
            android:background="@drawable/edit_states"
            android:src="@drawable/ic_action_edit"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"/>
    </RelativeLayout>


    <!-- Email -->
        <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="0.25"
        android:layout_marginTop="@dimen/activity_vertical_margin">

       <EditText 
            android:id="@+id/emailAddress"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/textview_border"
            android:hint="Enter sample text..."
            android:paddingTop="6dp"
            android:paddingBottom="8dp"
            android:paddingLeft="6dp"
            android:textSize="18sp"
            android:gravity="center_vertical"/>

       <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:contentDescription="Edit image icon"
            android:clickable="true"
            android:padding="4dp"
            android:layout_margin="8dp"
            android:scaleType="fitXY"
            android:background="@drawable/edit_states"
            android:src="@drawable/ic_action_edit"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"/>
    </RelativeLayout>


<!-- About You -->  
        <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="0.25"
        android:layout_marginTop="@dimen/activity_vertical_margin">

       <EditText 
            android:id="@+id/aboutUser"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/textview_border"
            android:hint="Enter sample text..."
            android:paddingTop="6dp"
            android:paddingBottom="8dp"
            android:paddingLeft="6dp"
            android:textSize="18sp"
            android:gravity="center_vertical"/>

       <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:contentDescription="Edit image icon"
            android:clickable="true"
            android:padding="4dp"
            android:layout_margin="8dp"
            android:scaleType="fitXY"
            android:background="@drawable/edit_states"
            android:src="@drawable/ic_action_edit"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"/>
    </RelativeLayout>


    <!-- Password -->
        <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="0.25"
        android:layout_marginTop="@dimen/activity_vertical_margin">

       <EditText 
            android:id="@+id/newPassword"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/textview_border"
            android:hint="Enter sample text..."
            android:paddingTop="6dp"
            android:paddingBottom="8dp"
            android:paddingLeft="6dp"
            android:textSize="18sp"
            android:gravity="center_vertical"/>

       <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:contentDescription="Edit image icon"
            android:clickable="true"
            android:padding="4dp"
            android:layout_margin="8dp"
            android:scaleType="fitXY"
            android:background="@drawable/edit_states"
            android:src="@drawable/ic_action_edit"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"/>
    </RelativeLayout>

        <TextView
            android:id="@+id/lastUpdate"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView" />

</LinearLayout>

i tried to use ScrollView but i had this error in LogCat

ScrollView can host only one direct child

so im looking for another solution maybe by code in the activity or something.

screenshot

1

There are 1 answers

1
Dazuku On BEST ANSWER

You should to put the content inside the ScrollView, like this

<LinearLayout 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="com.twaa9l.chates.MyProfile">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <RelativeLayout
                android:layout_weight="1.5"   
                android:layout_width="match_parent"
                android:layout_height="0dp">
                ...
            </RelativeLayout>
            ...
        </LinearLayout>
    </ScrollView>
</LinearLayout>