ViewPage+ListView效果

使用ViewPage+ListView做出如下图的效果:

[img]http://dl2.iteye.com/upload/attachment/0112/2362/fbe07f43-601c-3e6d-ac82-ca27a4275c93.png[/img]

设计思路如下:

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"
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值