【问题标题】:Android scroll over whole layout that has listviewAndroid滚动具有列表视图的整个布局
【发布时间】:2014-03-12 16:30:38
【问题描述】:

我正在尝试弄清楚如何设置这样的布局:

基本上,我想在用户滚动时实现这一点,他不仅在列表视图中滚动整个布局,它应该由 cmets 组成。据我所知,不推荐在ScrollView 中包含ListView。也可能在将来我想在ListView 和一些文本之间包含MapViewMapFragment。那么如何才能实现这样的布局呢?

【问题讨论】:

    标签: android listview scrollview


    【解决方案1】:

    您可以只添加一个ListView,并将“标题”和“一些文本”放在一个Header中。 以下是如何实现它: 对于标题,您应该创建一个布局:例如称为标题:`

                <TextView
                    android:id="@+id/title"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="title"
                   />
    
                <TextView
                    android:id="@+id/some_text"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="some text"
                   />
            </LinearLayout>
    

    `

    在您的活动中,您应该声明标题: LayoutInflater inflater = LayoutInflater.from(this); View header = inflater.inflate(R.layout.header, null);

    和:

    ListView yourListView;
     yourListView.addHeaderView(carouselBlock);
    

    在设置列表的适配器之前,您应该小心添加标题。

    【讨论】:

      【解决方案2】:

      根据 Guy Romain(Android 的主要开发人员之一)的说法,答案是使用 LinearLayout 而不是 Listview。你可以看到他的推理here

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-02-23
        • 1970-01-01
        • 2011-08-08
        • 2017-10-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多