2

我正在创建一个 android 应用程序,用户可以在其中在同一屏幕上查看频道列表和节目列表。例如:-

频道的图像将在左侧,已安排的节目将在右侧,用户可以水平滚动节目列表,由于频道很多,用户还可以垂直滚动整个布局。所有这一切都已实现,但我无法完成的是标题应该粘在顶部。

标题有 2 个部分:- 1. 简单图像视图位于图像频道列表上方的左侧,应保持顶部粘性且不可滚动 2. 时间列表标题,如 00:00 、 01:00 、 02:00上面图像视图的右侧和程序列表的上方,不应垂直滚动,但应可水平滚动。

以下是我用来显示布局的代码,我无法完成的是以上两点。他们只是不保持粘性,他们还会随着布局的其余部分上下滚动

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

                        <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content"
                                        android:layout_alignParentLeft="true" android:id="@+id/image_layout">
                                        <ImageView android:layout_gravity="center_vertical|center_horizontal" android:layout_width="wrap_content"
                                                   android:layout_height="wrap_content"  android:src="@drawable/tv_guide_channels" 
                                                   android:scaleType="fitCenter" android:id="@+id/channel_img_header"
                                                  android:layout_alignParentTop="true"/>
                                        <LinearLayout android:id="@+id/layout_to_add_channel_image" android:layout_width="wrap_content"
                                                      android:layout_height="wrap_content" android:orientation="vertical"
                                                      android:background="@color/White" android:layout_below="@id/channel_img_header" 
                                                      android:layout_alignParentBottom="true"/>
                       </RelativeLayout>

                       <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content"
                                       android:layout_alignParentRight="true" android:layout_toRightOf="@id/image_layout"
                                       android:id="@+id/programme_layout">
                                        <HorizontalScrollView android:layout_width="fill_parent" android:layout_height="wrap_content">
                                                        <RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content">
                                                                    <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content"
                                                                                    android:orientation="horizontal" android:id="@+id/table_header"
                                                                                    android:layout_alignParentTop="true">
                                                                    </LinearLayout>
                                                                    <ScrollView android:layout_width="fill_parent" android:layout_height="wrap_content"
                                                                                android:layout_below="@id/table_header">
                                                                    <RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content">
                                                                                    <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content"
                                                                                                    android:gravity="center_vertical" android:background="@color/greyblue"
                                                                                                    android:orientation="vertical" android:id="@+id/table_programme"
                                                                                                    android:layout_alignParentBottom="true">
                                                                                     </LinearLayout>    

                                                                        </RelativeLayout>
                                                                        </ScrollView>
                                                            </RelativeLayout>
                                         </HorizontalScrollView>
                       </RelativeLayout>

        </RelativeLayout>

<LinearLayout android:layout_height="2dip" android:layout_width="fill_parent" android:background="@color/Black"></LinearLayout>

4

3 回答 3

1

我知道这是一个老问题,发布我的答案,因为它会帮助其他正在寻找相同的人。
我出于同样的目的使用StickyScrollViewItems库。scrollView 内的任何视图都可以标记为“粘性”以使其在顶部具有粘性。

于 2015-09-02T01:39:25.317 回答
0

让您的 Header View 远离任何 ScrollView。

已编辑

嗨 Abhishek 受您问题的启发,我试图解决它。你可以在这里查看

于 2011-10-01T11:09:30.177 回答
0

好吧,感谢您的链接,但我找到了解决方案:-

人们总是可以使用自定义小部件,而且它也不那么可怕:) 在我的情况下,我曾经自定义滚动视图,并且在 xml 中提到了它们的包名+类名

例如:

<org.vision_asia.utils.MyScrollView1
android:id="@+id/sv1"
android:layout_below="@id/channel_img_header"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:scrollbars="none">

<LinearLayout
    android:background="@color/White"
    android:id="@+id/layout_to_add_channel_image"
    android:layout_alignParentBottom="true"
    android:layout_below="@id/channel_img_header"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:orientation="vertical" />

并且您希望将此 ScrollView 与其他滚动视图同步,这样如果用户滚动此滚动视图,那么同时另一个滚动视图必须滚动,就好像所有元素都仅在一个滚动视图下一样

public class MyScrollView1 extends ScrollView {

    public MyScrollView2 sv2;

    public MyScrollView1(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
    }

    public MyScrollView1(Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub
    }

    @Override
    protected void onScrollChanged(int l, int t, int oldl, int oldt) {
        // TODO Auto-generated method stub
        sv2.scrollTo(oldt, t);
        super.onScrollChanged(l, t, oldl, oldt);
    }
}

在您的主要活动中,您必须像这样调用自定义滚动视图:-

sv1 = (MyScrollView1)channelsList.findViewById(R.id.sv1);
sv1.sv2 = sv2;

其中 sv2 是应该同步的滚动视图

为了完全同步,您需要 2 个自定义滚动视图

享受

于 2011-10-04T12:06:20.020 回答