How to make a layout to be scrollable ? Android

Nikolas picture Nikolas · Mar 8, 2014 · Viewed 10.7k times · Source

Hi I am trying to create a layout which is going to contain a couple of image views a button and some text but the problem is that the layout is not scrollable. any idea of how I could implement that ? Many thanks in advance.

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

   <ImageView
    android:id="@+id/imageView1"
    android:layout_width="match_parent"
    android:layout_height="204dp"
    android:scaleType="fitXY"
    android:src="@drawable/pic11elit" android:contentDescription="ss"/>

   <TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="whatever"
    android:textAppearance="?android:attr/textAppearanceLarge" />

   <TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"

    android:textAppearance="?android:attr/textAppearanceMedium" />

  <TextView
    android:id="@+id/textView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Reservation No :27210 10020"
    android:textAppearance="?android:attr/textAppearanceMedium" />
         <Button
    android:id="@+id/On_back"
    style="?android:attr/buttonStyleSmall"
    android:layout_width="73dp"
    android:layout_height="wrap_content"
    android:onClick="On_back"
    android:text="back" />
      </LinearLayout>

Answer

Hamid Shatu picture Hamid Shatu · Mar 8, 2014

Try as below...

<?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" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="match_parent"
            android:layout_height="204dp"
            android:contentDescription="ss"
            android:scaleType="fitXY"
            android:src="@drawable/ic_launcher" />

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="whatever"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Reservation No :27210 10020"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <Button
            android:id="@+id/On_back"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="73dp"
            android:layout_height="wrap_content"
            android:onClick="On_back"
            android:text="back" />
    </LinearLayout>

</ScrollView>