为什么水平ScrollView无法正常工作?

时间:2017-03-24 03:05:27

标签: android scrollview android-tablelayout horizontalscrollview

我正在尝试使应用程序可以垂直滚动,并且在我的ScrollView内部并希望将Horizo​​ntalView水平滚动我的一些TableLayout,Scrollview工作正常,但水平可以滚动。我怎么解决这个问题?谢谢你的帮助。

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

我已经为我的孩子添加了一些代码Scrollview布局可以滚动,但它无法正常工作。

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;
           }
       });

1 个答案:

答案 0 :(得分:0)

您可以为此目的使用NestedScrollview: -

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