`

ViewPage+ListView效果

 
阅读更多
   使用ViewPage+ListView做出如下图的效果:



   设计思路如下:

   1. 一个总的fragment作为父,三个选项分别也是fragment, 父类布局:

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/common_title_bg"
        android:orientation="horizontal">

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="4"
            android:layout_marginTop="10dp"
            android:layout_marginBottom="10dp"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:orientation="horizontal"
            android:background="@drawable/bg_city_search_selector">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_marginLeft="15dp"
                android:src="@drawable/common_search_icon" />

            <EditText
                android:id="@+id/main_hall_search_txt"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="4"
                android:textSize="15sp"
                android:maxLength="15"
                android:singleLine="true"
                style="@style/common_edit_hint_drawable_style"
                android:paddingTop="10dp"
                android:paddingBottom="10dp"
                android:inputType="textNoSuggestions"
                android:hint="输入开发商名称" />

            <ImageView
                android:id="@+id/main_hall_search_delete_img"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                style="@style/right_icon_class"
                android:clickable="true"
                android:src="@drawable/input_right_delete_icon"/>
        </LinearLayout>

        <RelativeLayout
            android:id="@+id/main_hall_cancel_lyt"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:clickable="true"
            android:gravity="center">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                style="@style/top_text_big"
                android:text="@string/common_cancel"/>
        </RelativeLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="@dimen/main_hall_title_height"
        android:background="@color/xwhite"
        android:orientation="horizontal">

        <RelativeLayout
            android:id="@+id/main_hall_search_lyt_0"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:clickable="true"
            android:gravity="center">

            <TextView
                android:id="@+id/main_hall_txt_0"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                style="@style/main_hall_search_title"
                android:text="综合"/>

            <ImageView
                android:id="@+id/main_hall_img_0"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                style="@style/main_hall_select_style" />
        </RelativeLayout>

        <View
            android:layout_width="1dp"
            android:layout_height="match_parent"
            style="@style/middle_separate_horizontal_style_10"/>

        <RelativeLayout
            android:id="@+id/main_hall_search_lyt_1"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:clickable="true">

            <TextView
                android:id="@+id/main_hall_txt_1"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                style="@style/main_hall_search_title"
                android:text="好评"/>

            <ImageView
                android:id="@+id/main_hall_img_1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:visibility="invisible"
                style="@style/main_hall_select_style" />
        </RelativeLayout>

        <View
            android:layout_width="1dp"
            android:layout_height="match_parent"
            style="@style/middle_separate_horizontal_style_10"/>

        <RelativeLayout
            android:id="@+id/main_hall_search_lyt_2"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:clickable="true">

            <TextView
                android:id="@+id/main_hall_txt_2"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                style="@style/main_hall_search_title"
                android:text="砍价次数"/>

            <ImageView
                android:id="@+id/main_hall_img_2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:visibility="invisible"
                style="@style/main_hall_select_style" />
        </RelativeLayout>
    </LinearLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        style="@style/middle_separate"/>

    <android.support.v4.view.ViewPager
        android:id="@+id/main_hall_search_viewpage"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />


    2. 父类里面自定义了adapter,继承了FragmentStatePagerAdapter

public class LocalFragmentAdapter<T> extends FragmentStatePagerAdapter {

    private List<T> list;

    private Activity activity;

    public LocalFragmentAdapter(Fragment fm, List<T> list, Activity activity) {
        super(fm.getFragmentManager());
        this.list = list;
        this.activity = activity;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Fragment getItem(int i) {
        return (Fragment)list.get(i);
    }

    //用于刷新数据使用, 获取的查询字段放入缓存变量里面
    public void setSearchAndPosition(int currentPageIndex, Editable searchWord) {
        //用于刷新数据
        Fragment fragment = getItem(currentPageIndex);
        if (!TextUtils.isEmpty(searchWord)) {
            User.myself.mainHallSearchWord = searchWord.toString();
        } else {
            User.myself.mainHallSearchWord = null;
        }
        fragment.onResume();
        super.notifyDataSetChanged();
    }
}

    3. 父类代码
        //页面滚动
        main_hall_search_viewpage.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int i, float v, int i1) {
            }

            @Override
            public void onPageSelected(int position) {
                changeSelect(position);
                fragmentAdapter.setSearchAndPosition(currentPageIndex, main_hall_search_txt.getText());
            }

            @Override
            public void onPageScrollStateChanged(int i) {
            }
        });


        //搜索字段
        main_hall_search_txt.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void afterTextChanged(Editable editable) {
                fragmentAdapter.setSearchAndPosition(currentPageIndex, editable);
            }
        });


    4. 用于展示的三个子fragment使用LISTVIEW就可以, 配合适配器或自己定义的适配器


    注意:如果在每一个item里面还嵌套的有listview的话, 如针对某一个ITEM的多条回复
这个时候ITEM的焦点会被listview获取,有可能出现点item无响应的情况,需要在根目录下加:
android:descendantFocusability="blocksDescendants"
    
  • 大小: 27.9 KB
分享到:
评论

相关推荐

    Viewpage+Listview

    `ViewPager` 主要用于创建滑动页面的效果,而 `ListView` 则是展示可滚动的列表内容。当 `ViewPager` 需要与 `ListView` 结合使用时,可以构建出更复杂的布局,比如在一个页面中滑动查看多个列表内容。下面将详细...

    SlidingMenu+ViewPage+ListView嵌套(类似网易 ) ListView点击事件失效冲突问题解决

    在Android应用开发中,我们经常会遇到复杂布局的嵌套,比如`SlidingMenu`、`ViewPager`和`ListView`的组合。这样的设计可以为用户提供类似网易新闻客户端的体验,左侧是滑动菜单,中间是`ViewPager`用于切换不同的...

    android的viewpager+fragment+listView图片缓存

    `ListView`则是一种可以展示大量列表数据的视图,通常用于显示具有滚动效果的数据集合。结合适配器(如`BaseAdapter`或`ArrayAdapter`),`ListView`可以根据数据源动态生成并显示列表项。 在处理图片加载时,尤其...

    Frament+View+listViewDemo

    在这个`Frament+ViewPage+listViewDemo`中,我们将深入探讨如何利用这些组件实现一个滑动点击进入第二个`Activity`的效果。 首先,`Fragment`是Android中的一个模块化组件,它允许开发者将UI部分拆分为多个片段,每...

    天天动听源码,ViewPager套ViewPage,+ListView,ListView套GridView,再套SrcollView

    其余界面都简单,唯独是淘歌界面有点复杂, ViewPager中嵌套ViewPager+ListView,ListView中还嵌套GridView。由于要整屏滑动,所以在ViewPager+ListView外部嵌套个SrcollView,出现问题了ListView和SrcollView滑动 ...

    viewpage嵌套listview,效果:滑动listview删除,滑动非listview区域viewpage翻页

    标题"viewpage嵌套listview,效果:滑动listview删除,滑动非listview区域viewpage翻页"描述的就是这样一个功能:在ViewPager中嵌套了一个ListView,ListView支持滑动删除,而当滑动到ListView之外的区域时,...

    新闻首页效果[仿网易](ViewPager+Fragment+ListView)

    新闻首页效果[仿网易](ViewPager+Fragment+ListView), 1.添加fragment对象到fragment列表 2.添加title到title列表 3.从title列表中取出内容放到tabLayout容器中 4.创建并初始化适配器 5.为viewPager设定适配器 6....

    android 的 ListView +ViewPage+Fragmen+TabHost滑动效果

    在Android开发中,ListView、ViewPager、Fragment以及TabHost是构建复杂用户界面的四个核心组件,它们结合使用可以创建出丰富的滑动效果和交互体验。现在我们来深入探讨这些知识点。 首先,ListView是Android中用于...

    android ViewPage嵌套listview

    在Android开发中,`ViewPage`和`ListView`是两种常用的UI组件。`ViewPager`主要用于实现页面滑动的效果,常用于展示多个相似内容的页面,如应用的标签页。而`ListView`则是一个可以滚动显示多行数据的列表视图,适合...

    ScrollView+ViewPager+ListView或RecyclerView

    在Android开发中,`ScrollView`、`ViewPager`和`ListView`或`RecyclerView`是常见的UI组件,它们分别用于实现不同的滚动视图效果。本篇将深入探讨如何将这些组件组合使用,尤其是涉及到“加载更多”功能的实现。 ...

    android 通过向viewpage中添加listview来完成滑动效果(类似于qq滑动界面)

    在Android开发中,实现类似QQ滑动界面的效果通常涉及到`ViewPager`组件的使用,它可以创建一个可以左右滑动切换的页面容器。在这个场景下,我们不仅要实现`ViewPager`的滑动,还要在每个`ViewPager`的页面中嵌入`...

    Android引导页面的滑动实现,解决ViewPage侧滑与ListView滑动的冲突问题

    本文将深入探讨如何实现一个平滑的侧滑效果,并解决`ViewPage`与`ListView`滑动冲突的问题。 首先,我们要了解`ViewPage`的基本工作原理。`ViewPage`内部包含一个`PagerAdapter`,它管理着一系列的页面(通常是`...

    ViewPage中嵌套listVIew 进行轮播

    `ViewPager`通常用于实现水平滑动的页面切换效果,而`ListView`则用于展示垂直方向上的列表项。本文将详细介绍如何在`ViewPager`中嵌套`ListView`进行轮播。 首先,理解`ViewPager`的基本用法。`ViewPager`是...

    下拉刷新ListView+ViewPage

    在Android开发中,"下拉刷新ListView+ViewPage"是一个常见的功能组合,它结合了ListView的下拉刷新机制和ViewPager的图片无限自动切换效果。这个主题涵盖了多个关键知识点,包括ListView、ViewPager的基本使用,以及...

    抽屉 fragment 标签 左右滑动viewpage listview

    ViewPage是一种滑动页面的效果,常用于实现应用内部的水平滚动视图,如在浏览多个页面时进行左右切换。ListView则是一个可滚动的视图,通常用来显示大量的列表数据。 抽屉效果通常通过`SlidingMenu`库来实现,它...

    Android listview和viewpager解决冲突 滑动冲突

    Android listview viewpager 滑动 跳动 冲突解决 ListView中嵌套ViewPage有或者滑动手势冲突解决 blog 地址 : http://blog.csdn.net/aaawqqq/article/details/43824631

    listView添加ViewPager实现同时滑动

    当我们需要在一个列表项中嵌入多个页面视图时,将ListView与ViewPager结合使用就能达到同时滑动的效果。这个技术点通常出现在如电商应用的商品详情页,每个商品图片可以左右滑动查看,而整个商品列表则上下滚动。 ...

    网易新闻的listview

    在"仿网易新闻 viewpage"的设计中,我们看到两个关键功能的融合:一是ViewPager的页面切换,二是ListView的数据滚动。为了实现描述中的功能,开发者需要自定义适配器和交互逻辑。具体来说,可能涉及以下技术点: 1....

    listview添加头部viewpager

    可以通过监听ListView的滚动状态并在适当时机禁止ViewPager的滑动,或者使用第三方库如`androidx.swiperefreshlayout.widget.SwipeRefreshLayout`来封装整个布局,以实现更流畅的滑动效果。 总结起来,"listview...

Global site tag (gtag.js) - Google Analytics