manikanta gokavarapu
manikanta gokavarapu

Reputation: 39

I want to add Scroll View to the Buuton?

I want to add the scroll view to the relative layout because i had more buttons when i increase the buttons and run it on my mobile i cannot saw some buttons so i want to add the scroll view for button. How can i add it? Below is my xml code

<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:background="@drawable/background1">

      <include layout="@layout/header" />

        <include layout="@layout/footer" />

        <RelativeLayout 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/header"
            android:layout_above="@+id/footer"
    >

                <Button 
                    android:id="@+id/templesbtn"
                    android:layout_width="100dp"
                    android:layout_height="wrap_content"
                    android:text="Historical"
                    style="?android:attr/buttonStyleSmall"
                    android:background="@drawable/mymenubuttons"
                     android:layout_marginBottom="10dp"
                     android:layout_marginTop="10dp"/>
                <Button 
                    android:id="@+id/resortsbtn"
                    android:layout_width="100dp"
                    android:layout_height="wrap_content"
                    android:text="Resorts"
                    style="?android:attr/buttonStyleSmall"
                    android:background="@drawable/mymenubuttons"
                     android:layout_marginBottom="10dp"
                    android:layout_below="@+id/templesbtn"/>
                <Button 
                    android:id="@+id/shoppingmallsbtn"
                    android:layout_width="100dp"
                    android:layout_height="wrap_content"
                    android:text="Shopping"
                    style="?android:attr/buttonStyleSmall"
                    android:background="@drawable/mymenubuttons"
                    android:layout_marginBottom="10dp"
                    android:layout_below="@+id/resortsbtn"/>
                <Button 
                    android:id="@+id/theatersbtn"
                    android:layout_width="100dp"
                    android:layout_height="wrap_content"
                    android:text="Theaters"
                    style="?android:attr/buttonStyleSmall"
                    android:background="@drawable/mymenubuttons"
                     android:layout_marginBottom="10dp"
                    android:layout_below="@+id/shoppingmallsbtn"/>
                <Button 
                    android:id="@+id/restaurantsbtn"
                    android:layout_width="100dp"
                    android:layout_height="wrap_content"
                    android:text="Restaurants"
                    style="?android:attr/buttonStyleSmall"
                    android:background="@drawable/mymenubuttons"
                    android:layout_marginBottom="10dp"
                    android:layout_below="@+id/theatersbtn"
                    />

                <Button 
                    android:id="@+id/hospitalbtn"
                    android:layout_width="100dp"
                    android:layout_height="wrap_content"
                    android:text="Hospitals"
                    style="?android:attr/buttonStyleSmall"
                    android:background="@drawable/mymenubuttons"
                    android:layout_marginBottom="10dp"
                    android:layout_below="@+id/restaurantsbtn"
                    />

                  <Button 
                    android:id="@+id/collegebtn"
                    android:layout_width="100dp"
                    android:layout_height="wrap_content"
                    android:text="Colleges"
                    style="?android:attr/buttonStyleSmall"
                    android:background="@drawable/mymenubuttons"
                    android:layout_marginBottom="10dp"
                    android:layout_below="@+id/hospitalbtn"
                    />
                   <Button 
                    android:id="@+id/onlineservicebtn"
                    android:layout_width="100dp"
                    android:layout_height="wrap_content"
                    android:text="Online Services"
                    style="?android:attr/buttonStyleSmall"
                    android:background="@drawable/mymenubuttons"
                    android:layout_marginBottom="10dp"
                    android:layout_below="@+id/collegebtn"
                    />



      <RelativeLayout
          android:layout_toRightOf="@+id/templesbtn" 
          android:layout_width="match_parent"
        android:layout_height="wrap_content">

   <GridView
       android:id="@+id/gridView1"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:layout_alignParentLeft="true"
       android:layout_alignParentTop="true"
       android:numColumns="2"
       android:visibility="invisible" >
   </GridView>

 </RelativeLayout>

   </RelativeLayout>


</RelativeLayout>

can anyone help me?

Upvotes: 1

Views: 48

Answers (3)

secret08
secret08

Reputation: 48

May you could use ListView addHeaderView and addFooterView instead of ScrollView.

Upvotes: 0

Zubair Akber
Zubair Akber

Reputation: 2828

For more details on Scroll View visit

<ScrollView 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    // your child View
        // Buttons inside child View

</ScrollView>

Upvotes: 0

Tharindu Welagedara
Tharindu Welagedara

Reputation: 2725

First wrap your all buttons with a linearlayout(Vertical) then wrap that with a scrollview:

     <RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

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

        <LinearLayout

            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">
<Button 
                android:id="@+id/templesbtn"
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:text="Historical"
                style="?android:attr/buttonStyleSmall"
                android:background="@drawable/mymenubuttons"
                 android:layout_marginBottom="10dp"
                 android:layout_marginTop="10dp"/>
            <Button 
                android:id="@+id/resortsbtn"
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:text="Resorts"
                style="?android:attr/buttonStyleSmall"
                android:background="@drawable/mymenubuttons"
                 android:layout_marginBottom="10dp"
                android:layout_below="@+id/templesbtn"/>
            <Button 
                android:id="@+id/shoppingmallsbtn"
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:text="Shopping"
                style="?android:attr/buttonStyleSmall"
                android:background="@drawable/mymenubuttons"
                android:layout_marginBottom="10dp"
                android:layout_below="@+id/resortsbtn"/>
            <Button 
                android:id="@+id/theatersbtn"
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:text="Theaters"
                style="?android:attr/buttonStyleSmall"
                android:background="@drawable/mymenubuttons"
                 android:layout_marginBottom="10dp"
                android:layout_below="@+id/shoppingmallsbtn"/>
            <Button 
                android:id="@+id/restaurantsbtn"
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:text="Restaurants"
                style="?android:attr/buttonStyleSmall"
                android:background="@drawable/mymenubuttons"
                android:layout_marginBottom="10dp"
                android:layout_below="@+id/theatersbtn"
                />

            <Button 
                android:id="@+id/hospitalbtn"
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:text="Hospitals"
                style="?android:attr/buttonStyleSmall"
                android:background="@drawable/mymenubuttons"
                android:layout_marginBottom="10dp"
                android:layout_below="@+id/restaurantsbtn"
                />

              <Button 
                android:id="@+id/collegebtn"
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:text="Colleges"
                style="?android:attr/buttonStyleSmall"
                android:background="@drawable/mymenubuttons"
                android:layout_marginBottom="10dp"
                android:layout_below="@+id/hospitalbtn"
                />
               <Button 
                android:id="@+id/onlineservicebtn"
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:text="Online Services"
                style="?android:attr/buttonStyleSmall"
                android:background="@drawable/mymenubuttons"
                android:layout_marginBottom="10dp"
                android:layout_below="@+id/collegebtn"
                />

        </LinearLayout>
    </ScrollView>


    <RelativeLayout
        android:layout_toRightOf="@+id/scrollView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <GridView
            android:id="@+id/gridView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:numColumns="2"
            android:visibility="invisible"></GridView>

    </RelativeLayout>

</RelativeLayout>

Upvotes: 1

Related Questions