Vivek Shankar
Vivek Shankar

Reputation: 701

Android Horizontal Scroll View

i have a layout having many fields and i wish to add scrollbars for both horizontal and vertical layout.But vertical scroll is working horizontal scroll is not working.I have loaded the text fields dynamically in program and add the fields with web service .

My Activity

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LayoutScroll"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:scrollbars="horizontal|vertical" >

<LinearLayout
    android:id="@+id/linearLayout2"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginBottom="10dp"
    android:layout_marginTop="30dp"
    android:gravity="fill|fill_horizontal"
    android:orientation="vertical" >

      <TableRow
          android:id="@+id/Row_User_Deletion"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:background="#DF0101"
          android:gravity="center" >

         <TextView
             android:id="@+id/user_creation_id"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="@string/txt_delete_user_userDeletion"
             android:textColor="@color/white"
             android:textSize="15dp" />
     </TableRow>

      <TableRow
          android:id="@+id/RowUserType"
          android:layout_width="match_parent"
          android:layout_height="45dp"
          android:layout_marginTop="10dp" >

          <TextView
              android:id="@+id/txt_delete_user_selectuserType"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginTop="5dp"
              android:text="@string/txt_delete_user_selectuserType"
              android:textColor="#424242" />

          <Spinner
              android:id="@+id/spin_delete_userType"
              android:layout_width="120dp"
              android:layout_height="50dp"
              android:layout_marginBottom="5dp"
              android:entries="@array/utype" />

          <Button
              android:id="@+id/btn_spinner_user_search_select"
              style="?android:attr/buttonStyleSmall"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginLeft="25dp"
              android:layout_marginTop="5dp"
              android:background="@drawable/redbtn"
              android:text="@string/btn_delete_user_search_user" />

      </TableRow>

    <TableRow
        android:id="@+id/deleteUserRow"
        android:layout_width="match_parent"
        android:layout_height="34dp"
        android:layout_marginTop="10dp"
        android:gravity="fill" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/txt_user_creation_userId"
            android:textColor="#424242" />

        <EditText
            android:id="@+id/txt_user_delete"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="5dp"
            android:ems="10" >

            <requestFocus />
        </EditText>

        <Button
            android:id="@+id/button1"
            android:layout_width="55dp"
            android:layout_height="wrap_content"
            android:layout_marginRight="5dp"
            android:background="@drawable/redbtn"
            android:text="@string/btn_delete_user_search_user" />

        </TableRow>


         <TableLayout
             android:id="@+id/delete_userDetails_Table"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_marginTop="5dp"
             android:orientation="vertical"
             android:stretchColumns="*" >

            <TableRow
                android:id="@+id/tableRow2"
                android:layout_width="fill_parent"
                android:layout_height="match_parent"
                android:layout_marginTop="5dp"
                android:background="@color/red" >

                <TextView
                    android:id="@+id/textView2"
                    android:layout_width="fill_parent"
                    android:layout_height="match_parent"
                    android:text="@string/txt_delete_user_select"
                    android:textColor="@color/white" />

                <TextView
                    android:id="@+id/textView3"
                    android:layout_width="fill_parent"
                    android:layout_height="match_parent"
                    android:text="@string/txt_user_creation_userId"
                    android:textColor="@color/white" />

                <TextView
                    android:id="@+id/textView4"
                    android:layout_width="fill_parent"
                    android:layout_height="match_parent"
                    android:text="@string/txt_user_creation_userName"
                    android:textColor="@color/white" />

                <TextView
                    android:id="@+id/textView5"
                    android:layout_width="fill_parent"
                    android:layout_height="match_parent"
                    android:text="@string/txt_delete_user_UserRole"
                    android:textColor="@color/white" />

                <TextView
                    android:id="@+id/textView5"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/txt_componentmaster_createdDate"
                    android:textColor="@color/white" />

                <TextView
                    android:id="@+id/textView5"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/txt_componentmaster_createdBy"
                    android:textColor="@color/white" />
            </TableRow>
        </TableLayout>

    </LinearLayout>
</ScrollView>

ImageView

enter image description here

Upvotes: 1

Views: 4295

Answers (2)

Shreyash Mahajan
Shreyash Mahajan

Reputation: 23606

Please keep in mind that the view that you want to scroll Horizontal is must have LinearLayout as parent then only you can set the HorizontalScrollView between that layout.

And Put one HorizontalScrollView as the Parent of those both LinearLayout.

Hope this will help you.

Smple:

<HORIZONTAL_VIEW ... >

 <!-- Your First Layout -->
 <LinearLayout ... >

 </LinearLayout>

 <!-- Your Second Layout -->
 <LinearLayout ... >

 </LinearLayout>

 </HORIZONTAL_VIEW ... >

Hope you got my point.

Feel free for any query. :)

Upvotes: 2

gowri
gowri

Reputation: 681

Try the Scroll Bars with out the Scrollview..

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

android:id="@+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="10dp"
android:layout_marginTop="30dp"
android:gravity="fill|fill_horizontal"
android:scrollbars="horizontal|vertical"
android:orientation="vertical" >

  <TableRow
      android:id="@+id/Row_User_Deletion"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="#DF0101"
      android:gravity="center" >

     <TextView
         android:id="@+id/user_creation_id"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="@string/txt_delete_user_userDeletion"
         android:textColor="@color/white"
         android:textSize="15dp" />
 </TableRow>

  <TableRow
      android:id="@+id/RowUserType"
      android:layout_width="match_parent"
      android:layout_height="45dp"
      android:layout_marginTop="10dp" >

      <TextView
          android:id="@+id/txt_delete_user_selectuserType"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginTop="5dp"
          android:text="@string/txt_delete_user_selectuserType"
          android:textColor="#424242" />

      <Spinner
          android:id="@+id/spin_delete_userType"
          android:layout_width="120dp"
          android:layout_height="50dp"
          android:layout_marginBottom="5dp"
          android:entries="@array/utype" />

      <Button
          android:id="@+id/btn_spinner_user_search_select"
          style="?android:attr/buttonStyleSmall"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginLeft="25dp"
          android:layout_marginTop="5dp"
          android:background="@drawable/redbtn"
          android:text="@string/btn_delete_user_search_user" />

  </TableRow>

<TableRow
    android:id="@+id/deleteUserRow"
    android:layout_width="match_parent"
    android:layout_height="34dp"
    android:layout_marginTop="10dp"
    android:gravity="fill" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/txt_user_creation_userId"
        android:textColor="#424242" />

    <EditText
        android:id="@+id/txt_user_delete"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="5dp"
        android:ems="10" >

        <requestFocus />
    </EditText>

    <Button
        android:id="@+id/button1"
        android:layout_width="55dp"
        android:layout_height="wrap_content"
        android:layout_marginRight="5dp"
        android:background="@drawable/redbtn"
        android:text="@string/btn_delete_user_search_user" />

    </TableRow>


     <TableLayout
         android:id="@+id/delete_userDetails_Table"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_marginTop="5dp"
         android:orientation="vertical"
         android:stretchColumns="*" >

        <TableRow
            android:id="@+id/tableRow2"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="5dp"
            android:background="@color/red" >

            <TextView
                android:id="@+id/textView2"
                android:layout_width="fill_parent"
                android:layout_height="match_parent"
                android:text="@string/txt_delete_user_select"
                android:textColor="@color/white" />

            <TextView
                android:id="@+id/textView3"
                android:layout_width="fill_parent"
                android:layout_height="match_parent"
                android:text="@string/txt_user_creation_userId"
                android:textColor="@color/white" />

            <TextView
                android:id="@+id/textView4"
                android:layout_width="fill_parent"
                android:layout_height="match_parent"
                android:text="@string/txt_user_creation_userName"
                android:textColor="@color/white" />

            <TextView
                android:id="@+id/textView5"
                android:layout_width="fill_parent"
                android:layout_height="match_parent"
                android:text="@string/txt_delete_user_UserRole"
                android:textColor="@color/white" />

            <TextView
                android:id="@+id/textView5"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="@string/txt_componentmaster_createdDate"
                android:textColor="@color/white" />

            <TextView
                android:id="@+id/textView5"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="@string/txt_componentmaster_createdBy"
                android:textColor="@color/white" />
        </TableRow>
    </TableLayout>

</LinearLayout>

Upvotes: 1

Related Questions