Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ScrollView包括Android中的ListView_Android_Android Layout_Android Listview_Android Scrollview - Fatal编程技术网

ScrollView包括Android中的ListView

ScrollView包括Android中的ListView,android,android-layout,android-listview,android-scrollview,Android,Android Layout,Android Listview,Android Scrollview,我想要一个滚动视图,其中包含列表视图,这显然是不可取的,因为列表视图有自己的滚动条 基本上,我希望有一个相对论页面,页面的页眉包含多个视图,然后是一个列表视图,类似于Facebook的个人资料页面,页面的图片后面是提要 如果我只是将一个ListView放在RelativeLayout中,那么只有ListView区域是可滚动的,而不是整个页面 有没有办法不将标题(RelativeLayout)作为列表视图中的第一个元素?事实上,我自己并没有这样做,但我知道实现目标的诀窍,让布局看起来性感。 首先去

我想要一个
滚动视图
,其中包含
列表视图
,这显然是不可取的,因为
列表视图
有自己的滚动条

基本上,我希望有一个
相对论页面
,页面的页眉包含多个视图,然后是一个
列表视图
,类似于Facebook的个人资料页面,页面的图片后面是提要

如果我只是将一个
ListView
放在
RelativeLayout
中,那么只有
ListView
区域是可滚动的,而不是整个页面


有没有办法不将标题(
RelativeLayout
)作为
列表视图中的第一个元素?

事实上,我自己并没有这样做,但我知道实现目标的诀窍,让布局看起来性感。 首先去掉那个滚动视图。 然后在ListVIEW上设置监视器(侦听器),以检测ListVIEW滚动了多少,并考虑一个合理的阈值来检测*。 现在什么是*?这是你应该“隐藏”或“慢慢淡出”你的标题项目的时候了。当用户向下滚动ListView并达到该阈值时,会慢慢淡出或隐藏标题。然后,当用户向上滚动时,再次使用阈值来决定何时使标题项可见。 据我所知,这就是我的想法。还可以尝试检查github和android阿森纳,我想应该有一个用于此的库,可以简化您的工作。

试试这段代码

  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="10dp" >

        <LinearLayout
            android:id="@+id/headerLayout"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="TextView" />

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="TextView" />
        </LinearLayout>

        <ListView
            android:id="@+id/listView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/headerLayout" >
        </ListView>

    </RelativeLayout>

ListView上似乎有一个名为addHeaderView的方法。我可以用它在顶部添加RelativeLayout。感谢您的输入。

使用此类
    Use this class

    public class Helper {

       public static void getListViewSize(ListView myListView) {
           ListAdapter myListAdapter = myListView.getAdapter();
           if (myListAdapter == null) {
    //           do nothing return null
               return;
           }
           //set listAdapter in loop for getting final size
           int totalHeight = 0;

           for (int size = 0; size < myListAdapter.getCount(); size++) {
               View listItem = myListAdapter.getView(size, null, myListView);
               listItem.measure(0, 0);
               totalHeight += listItem.getMeasuredHeight();
           }
         //setting listview item in adapter
           ViewGroup.LayoutParams params = myListView.getLayoutParams();
           params.height = totalHeight + (myListView.getDividerHeight() * (myListAdapter.getCount() - 1));
           myListView.setLayoutParams(params);
           // print height of adapter on log
           Log.i("height of listItem:", String.valueOf(totalHeight));
       }
    }

and in the activity class, use,

Helper.getListViewSize(ur listview name);
公营助理员{ 公共静态无效getListViewSize(ListView myListView){ ListAdapter myListAdapter=myListView.getAdapter(); if(myListAdapter==null){ //不执行任何操作返回空值 返回; } //在循环中设置listAdapter以获取最终大小 int totalHeight=0; 对于(int size=0;size
有一种方法,但无论哪种方法,其中一种都不会滚动,请尝试重新考虑您的布局结构。您能详细说明一下吗?ListView将被无限滚动,我只需要在滚动中包含的视图顶部有标题布局。那么让我为这个问题添加一个答案。如果它解决了您的问题,请投票并标记为已解决,如果它没有或您不理解下面的评论,我会回答。这是一个解决办法,但不是我要求的解决方案。