简体   繁体   English

Android:垂直和水平滚动,顶部和左侧受限制

[英]Android:Vertical and horizontal scrolling with constrains on top and left

I would like to implement the following scroll view with vertical and horizontal scrolling: 我想通过垂直和水平滚动实现以下滚动视图:

       9:00    9:30    10:00    10:30    11:00    ...
item1  hi11    hi12    hi13     hi14     hi15     ...
item2  hi21    hi22    hi23     hi24     hi25     ...
item3  hi31    hi32    hi33     hi34     hi35     ...
...    ...     ...     ...      ...      ...      ...

but in addition I would like to apply the following two constrains: 但除此之外,我想应用以下两个约束:

1) If the user scrolls, from down to top, the area filled with "hi"; 1)如果用户从下到上滚动到充满“ hi”的区域; then the first row (time) must remain visible: 那么第一行(时间)必须保持可见:

2) If the user scrolls, from right to left, the area filled with "hi"; 2)如果用户从右向左滚动填充“ hi”的区域; then the first column (item1, item2, ...) must remain visible. 那么第一列(item1,item2,...)必须保持可见。

So, after scrolling vertical and horizontally the view can have the following appearance: 因此,在垂直和水平滚动后,视图可以具有以下外观:

        16:00   16:30   17:00    17:30    18:00   ...
item23  abc     cde     efg      gfr      dfr     ...
item24  cvd     qwe     aqw      asw      dfr     ...
item25  dle     zwq     wer      ser      zzz     ...
...     ...     ...     ...      ...      ...     ...

The solution that I have found so far is based on Layouts and also creating items dynamically; 到目前为止,我发现的解决方案基于Layouts并且还可以动态创建项目。 however this solution has the problem of not synchronising the horizontal scrolling in the central area (hi11, hi12, hi13) with the time row (9:00 9:30 10:00 ...). 但是,该解决方案具有以下问题:中心区域(hi11,hi12,hi13)中的水平滚动与时间行(9:00 9:30 10:00 ...)不同步。

So, I need a way to detect horizontal scrolling in the "central area" and apply the same horizontal scroll to the "time area" (and, if possible, vice versa). 因此,我需要一种方法来检测“中央区域”中的水平滚动并将相同的水平滚动应用于“时间区域”(如果可能,反之亦然)。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

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

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

            <LinearLayout
                android:id="@+id/epg_time_list"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal" />
                 <!-- In code: Create several TextView's time 
                  items and add them to this layout in order to
                  to create the first row which shows the time HH:mm -->

        </LinearLayout>
    </HorizontalScrollView>

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

        <LinearLayout
            android:id="@+id/epg_channel_list_master_master"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <LinearLayout
                android:id="@+id/epg_channel_list_master_detail"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal" >

                <LinearLayout
                    android:id="@+id/epg_channel_list_master"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="vertical" >

                    <!-- In code: Create a TextView for every item
                      to create the first column (item1, item2, ...) -->

                </LinearLayout>

                <HorizontalScrollView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" >

                        <LinearLayout
                            android:id="@+id/epg_channel_list_detail_container"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:orientation="vertical" >


                            <!-- In code: Create a horizontal LinearLayout for
                            every row. Every row will contain several
                            TextViews with short names -->

                        </LinearLayout>
                </HorizontalScrollView>
            </LinearLayout>
        </LinearLayout>
    </ScrollView>

</LinearLayout>

I have found a solution based on setting "onTouchListener" for every one of both horizontal scroll views; 我发现了一个基于为两个水平滚动视图中的每个视图都设置“ onTouchListener”的解决方案。 consequently I have added in the .xml two new identifiers (one for every horizontal scroll view), and in the code I have "setOnTouchListener" for every one of the aforementioned "horizontal scroll views to listen to each other; that is: 因此,我在.xml中添加了两个新的标识符(每个水平滚动视图一个),并且在代码中,我为上述每个“水平滚动视图”添加了“ setOnTouchListener”以相互听;即:

    mDetailHorizontalScrollView = (HorizontalScrollView) view
    .findViewById(R.id.detail_horizontal_scroll_view);
    mDetailHorizontalScrollView.setOnTouchListener(new OnTouchListener(){

        @Override
        public boolean onTouch(View view, MotionEvent event) {
            int scrollX = view.getScrollX();
            int scrollY = view.getScrollY();

            mEpgTimeHorizontalScrollView.scrollTo(scrollX, scrollY);
                        return false;
            }

        });


    mEpgTimeHorizontalScrollView = (HorizontalScrollView) view
            .findViewById(R.id.epg_time_horizontal_scroll_view);
    mEpgTimeHorizontalScrollView.setOnTouchListener(new OnTouchListener(){

        @Override
        public boolean onTouch(View view, MotionEvent event) {
            int scrollX = view.getScrollX();
            int scrollY = view.getScrollY();

            mDetailHorizontalScrollView.scrollTo(scrollX, scrollY);
                        return false;
            }

        });

And the identifiers for those horizontal scroll views are set up in the code according to the xml: 然后根据xml在代码中设置这些水平滚动视图的标识符:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <HorizontalScrollView
        android:id="@+id/epg_time_horizontal_scroll_view"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

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

            <LinearLayout
                android:id="@+id/epg_time_list"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal" />
                 <!-- In code: Create several TextView's time 
                  items and add them to this layout in order to
                  to create the first row which shows the time HH:mm -->
        </LinearLayout>
    </HorizontalScrollView>

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

        <LinearLayout
            android:id="@+id/epg_channel_list_master_master"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <LinearLayout
                android:id="@+id/epg_channel_list_master_detail"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal" >

                <LinearLayout
                    android:id="@+id/epg_channel_list_master"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="vertical" >

                    <!-- In code: Create a TextView for every item
                    to create the first column (item1, item2, ...) -->

                </LinearLayout>

                <HorizontalScrollView
                    android:id="@+id/detail_horizontal_scroll_view"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" >

                        <LinearLayout
                            android:id="@+id/epg_channel_list_detail_container"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:orientation="vertical" >


                        <!-- In code: Create a horizontal LinearLayout for
                        every row. Every row will contain several
                        TextViews with short names -->

                        </LinearLayout>
                </HorizontalScrollView>
            </LinearLayout>
        </LinearLayout>
    </ScrollView>

</LinearLayout>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM