0

i am trying to make application can scrolled vertically, and inside my ScrollView and want put HorizontalView to scroll horizontal some of my TableLayout, Scrollview is working perfectly but the Horizontal Can't Scroll. How can i solve this? Thanks for your help.

<HorizontalScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fillViewport="true"        >
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <TableLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"

                android:id="@+id/tablejdl"
                android:weightSum="7"
                android:layout_marginTop="20dp"
                >

                <TableRow
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:weightSum="7"
                    android:gravity="center_horizontal">

                    <TextView
                        android:textColor="#ffffff"
                        android:layout_marginTop="10dp"

                        android:layout_width="0dp"
                        android:textSize="11sp"
                        android:layout_height="wrap_content"
                        android:text="Barang"
                        android:layout_weight="2"
                        android:id="@+id/kodebar"
                        />
                    <TextView
                        android:textColor="#ffffff"
                        android:layout_marginTop="10dp"

                        android:layout_width="0dp"
                        android:textSize="11sp"
                        android:layout_height="wrap_content"
                        android:text="Jumlah"
                        android:layout_weight="1"
                        android:id="@+id/jumlah"
                        />
                    <TextView
                        android:textColor="#ffffff"
                        android:layout_marginTop="10dp"

                        android:layout_width="0dp"
                        android:textSize="11sp"
                        android:layout_height="wrap_content"
                        android:text="Sup1"
                        android:layout_weight="1"
                        android:id="@+id/namabar"/>
                    <TextView
                        android:textColor="#ffffff"
                        android:layout_marginTop="10dp"

                        android:layout_width="0dp"
                        android:textSize="11sp"
                        android:layout_height="wrap_content"
                        android:text="Sup2"
                        android:layout_weight="1"
                        android:id="@+id/jumlahbar"/>

                    <TextView
                        android:textColor="#ffffff"
                        android:layout_marginTop="10dp"
                        android:layout_width="0dp"
                        android:textSize="11sp"
                        android:layout_height="wrap_content"
                        android:text="Sup3"
                        android:layout_weight="4"
                        android:id="@+id/stokbar"/>
                    <TextView
                        android:textColor="#ffffff"
                        android:layout_marginTop="10dp"

                        android:layout_width="0dp"
                        android:textSize="11sp"
                        android:layout_height="wrap_content"
                        android:text="Total"
                        android:layout_weight="2"
                        android:id="@+id/jtotal"/>
                </TableRow>
            </TableLayout>

                <android.support.v7.widget.RecyclerView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_below="@id/tablejdl"
                    android:id="@+id/recyclerpenawaran">
                </android.support.v7.widget.RecyclerView>

            <TableLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/recyclerpenawaran"
                android:id="@+id/tablejdl2"
                android:weightSum="7"
                android:layout_marginTop="15dp"
                >
                <TableRow
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:weightSum="7"
                    android:gravity="center_horizontal">

                    <TextView
                        android:textColor="#ffffff"
                        android:layout_marginTop="10dp"
                        android:layout_width="0dp"
                        android:textSize="11sp"
                        android:layout_height="wrap_content"
                        android:layout_weight="2"
                        />
                    <TextView
                        android:textColor="#ffffff"
                        android:layout_marginTop="10dp"
                        android:layout_width="0dp"
                        android:textSize="11sp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"

                        />
                    <CheckBox
                        android:textColor="#ffffff"
                        android:layout_marginTop="10dp"
                        android:layout_width="0dp"
                        android:textSize="11sp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:id="@+id/checksup1"/>
                    <CheckBox
                        android:textColor="#ffffff"
                        android:layout_marginTop="10dp"
                        android:layout_width="0dp"
                        android:textSize="11sp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:id="@+id/checksup2"/>

                    <CheckBox
                        android:textColor="#ffffff"
                        android:layout_marginTop="10dp"

                        android:layout_width="0dp"
                        android:textSize="11sp"
                        android:layout_height="wrap_content"

                        android:layout_weight="1"
                        android:id="@+id/checksup3"/>
                    <TextView
                        android:textColor="#ffffff"
                        android:layout_marginTop="10dp"
                        android:layout_width="0dp"
                        android:textSize="11sp"
                        android:layout_height="wrap_content"
                        android:text="Total"
                        android:layout_weight="1"
                        android:id="@+id/total"/>
                </TableRow>
            </TableLayout>
        </RelativeLayout>
    </LinearLayout>
</HorizontalScrollView>

I have add some code to my child Scrollview layout can Scrolled, but its not going to work.

scrool = (ScrollView)findViewById(R.id.vertical);
        scrollView = (HorizontalScrollView)findViewById(R.id.horizontal);
        scrool.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                scrollView.getParent().requestDisallowInterceptTouchEvent(false);
                return false;
            }
        });

       scrollView.setOnTouchListener(new View.OnTouchListener() {
           @Override
           public boolean onTouch(View v, MotionEvent event) {

               v.getParent().requestDisallowInterceptTouchEvent(true);
               return false;
           }
       });
Denny Kurniawan
  • 168
  • 1
  • 3
  • 21
  • 1
    Because your HorizontalScrollView is in another scrollbar which also has the same vertical scrolling ability. Disable the parent vertical scrolling should work. – K.Sopheak Mar 24 '17 at 03:30
  • 1
    Thanks for your answer, but i want to vertical Scroll in my application too. @K.Sopheak – Denny Kurniawan Mar 24 '17 at 03:32
  • try using recyclerview only, you don't need that horizontalscrollview viewgroup. RecyclerView has got more newer methods, which can be easily implemented. – Manoj Perumarath Mar 24 '17 at 03:45
  • 1
    So you can disable the parent scroll view when you scroll the child scroll view. Let look at this answers may help. http://stackoverflow.com/q/4767519/5241603 and http://stackoverflow.com/q/6210895/5241603 – K.Sopheak Mar 24 '17 at 03:47

1 Answers1

0

You can make use of NestedScrollview for this purpose:-

 <android.support.v4.widget.NestedScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent">
 <HorizontalScrollView
                 android:layout_width="wrap_content"
                android:layout_height="match_parent">
                 ...... 
 </HorizontalScrollView>
 </android.support.v4.widget.NestedScrollView>
Karan Kalsi
  • 789
  • 3
  • 21
  • 1
    you need to do changes in both, in code change this :- scrool = (NestedScrollView)findViewById(R.id.vertical); – Karan Kalsi Mar 24 '17 at 08:08