ohnoits kixkix ohnoits kixkix - 15 days ago 6
Android Question

Multiple linear layout with Scroll view?

What I'm trying to achieve is this:

enter image description here

But what I have is:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"

android:layout_width="290dp"
android:layout_height="490dp"
android:layout_marginLeft="35dp"
android:layout_marginTop="40dp"
android:background="#2a873e"
tools:context="com.sumo.traffic.PlacesFilters"
android:orientation="vertical">

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >

<Button
android:id="@+id/button1"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:text="Button" />

<Button
android:id="@+id/button2"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight="0.6"
android:text="Button" />

</LinearLayout>


<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >

<Button
android:id="@+id/button3"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:text="Button" />

<Button
android:id="@+id/button4"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight="0.6"
android:text="Button" />

</LinearLayout>



</LinearLayout>


When applying scroll view it shows that the scroll view can only host one single layout.
Would there be another possible way to produce what I want to achieve?

I'm putting more than 10 buttons in a single activity that's why i need a scrollview in my layout.

Answer

Try to use this :

<?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" >
  <ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

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

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/button1"
                android:layout_width="0px"
                android:layout_height="wrap_content"
                android:layout_weight="0.4"
                android:text="Button" />

            <Button
                android:id="@+id/button2"
                android:layout_width="0px"
                android:layout_height="wrap_content"
                android:layout_weight="0.6"
                android:text="Button" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/button3"
                android:layout_width="0px"
                android:layout_height="wrap_content"
                android:layout_weight="0.4"
                android:text="Button" />

            <Button
                android:id="@+id/button4"
                android:layout_width="0px"
                android:layout_height="wrap_content"
                android:layout_weight="0.6"
                android:text="Button" />
        </LinearLayout>
    </LinearLayout>
</ScrollView></LinearLayout>
Comments