English 中文(简体)
• 如何在像头盔这样的屏幕上使某些get子无法接种或 stick
原标题:How to make certain widgets in scroll view unscrollable or sticky at the top of screen like a header

I am creating an android application in which the user can view the channel list and programme list on the same screen. For ex :-

The image of the channel will be on left and the programmes scheduled will be on the right and the user can horizontally scroll the programme listing and since there will be many channels the user can also scroll the complete layout vertically. All this has been implemented but what i can not get done is the header should be sticky at the top.

The header has 2 parts :- 1. Simple Image View on left side above the channels list of images and should remain sticky at top and not be scrollable 2. Timings list header like 00:00 , 01:00 , 02:00 on the right of the above image view and on the above of the programme list and should not be scrollable vertically but should be scrollable horizontally.

The following is the code that i am using to display the layout all i can not get it done are the above two points. They just dont remain sticky they also scroll up and down with the rest of layout

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

最佳回答

很好地感谢这一联系,但我找到解决办法:

One can always use custom widgets and its not that scary also :) In my case i used to custom scroll views and in xml mentioned their packagename+className

具体如下:

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

并且,你希望将这一意见与其他意见同步进行,这样,如果用户浏览这种滚动观点,那么其他的滚动观点必须同时进行,因为所有要素都只服从一种滚动观点。

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;

如果是零2,则应同步进行。

为使您完全同步,需要2项习俗发展观

休闲

问题回答

I know this is an old question, posting my answer as it would help others who is looking for same.
I use StickyScrollViewItems library for the same purpose. Any view inside the scrollView can be tagged as Sticky to make it sticky at top.

您 Header View out of any ScrollView.

Edited

Hi Abhishek By inspiration of your problem I have tried to solve it. You can check it here





相关问题
how to represent it in dtd?

I have two element action and guid. guid is a required field when action is add. but when action is del it will not appear in file. How to represent this in dtd ?

.Net application configuration add xml-data

I need to add xml-content to my application configuration file. Is there a way to add it directly to the appSettings section or do I need to implement a configSection? Is it possible to add the xml ...

XStream serializing collections

I have a class structure that I would like to serialize with Xstream. The root class contains a collection of other objects (of varying types). I would like to only serialize part of the objects that ...

MS Word splits words in its XML format

I have a Word 2003 document saved as a XML in WordProcessingML format. It contains few placeholders which will be dynamically replaced by an appropriate content. But, the problem is that Word ...

Merging an XML file with a list of changes

I have two XML files that are generated by another application I have no control over. The first is a settings file, and the second is a list of changes that should be applied to the first. Main ...

How do I check if a node has no siblings?

I have a org.w3c.dom.Node object. I would like to see if it has any other siblings. Here s what I have tried: Node sibling = node.getNextSibling(); if(sibling == null) return true; else ...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

热门标签