try
IndexableRecyclerView
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical">
<me.yokeyword.indexablerv.IndexableLayout android:id="@+id/indexableLayout" android:layout_width="match_parent" android:layout_height="match_parent" app:indexBar_background="#08000000" app:indexBar_layout_width="50dp" app:indexBar_textColor="@android:color/black" app:indexBar_textSpace="8dp"/>
LinearLayout>
public class FragmentMovie extends BaseFragment {
private List mDatas;
private SimpleHeaderAdapter mHotCityAdapter;
@Override
protected int getLayoutId() {
return R.layout.fragment_movie;
}
@Override
protected void initView(View view) {
IndexableLayout indexableLayout = (IndexableLayout) view.findViewById(R.id.indexableLayout);
indexableLayout.setLayoutManager(new GridLayoutManager(this.getContext(), 1));
// setAdapter
CityAdapter adapter = new CityAdapter(this.getContext());
indexableLayout.setAdapter(adapter);
// set Datas
mDatas = initDatas();
// 快速排序。 排序规则设置为:只按首字母 (默认全拼音排序) 效率很高,是默认的10倍左右。 按需开启~
indexableLayout.setCompareMode(IndexableLayout.MODE_FAST);
adapter.setDatas(mDatas, new IndexableAdapter.IndexCallback() {
@Override
public void onFinished(List> datas) {
// 数据处理完成后回调
// mSearchFragment.bindDatas(mDatas);
// mProgressBar.setVisibility(View.GONE);
}
});
// set Center OverlayView
// indexableLayout.setOverlayStyle_Center();
adapter.setOnItemContentClickListener(new IndexableAdapter.OnItemContentClickListener() {
@Override
public void onItemClick(View v, int originalPosition, int currentPosition, CityEntity entity) {
}
});
// set Listener
adapter.setOnItemContentClickListener(new IndexableAdapter.OnItemContentClickListener() {
@Override
public void onItemClick(View v, int originalPosition, int currentPosition, CityEntity entity) {
if (originalPosition >= 0) {
ToastUtil.showShort(getContext(), "选中:" + entity.getName() + " 当前位置:" + currentPosition + " 原始所在数组位置:" + originalPosition);
} else {
ToastUtil.showShort(getContext(), "选中Header:" + entity.getName() + " 当前位置:" + currentPosition);
}
}
});
adapter.setOnItemTitleClickListener(new IndexableAdapter.OnItemTitleClickListener() {
@Override
public void onItemClick(View v, int currentPosition, String indexTitle) {
ToastUtil.showShort(getContext(), "选中:" + indexTitle + " 当前位置:" + currentPosition);
}
});
// 添加 HeaderView DefaultHeaderAdapter接收一个IndexableAdapter, 使其布局以及点击事件和IndexableAdapter一致
// 如果想自定义布局,点击事件, 可传入 new IndexableHeaderAdapter
mHotCityAdapter = new SimpleHeaderAdapter<>(adapter, "热门", "热门城市", iniyHotCityDatas());
// 热门城市
indexableLayout.addHeaderAdapter(mHotCityAdapter);
// 定位
final List gpsCity = iniyGPSCityDatas();
final SimpleHeaderAdapter gpsHeaderAdapter = new SimpleHeaderAdapter<>(adapter, "定位", "当前城市", gpsCity);
indexableLayout.addHeaderAdapter(gpsHeaderAdapter);
// 显示真实索引
// indexableLayout.showAllLetter(false);
// 模拟定位
indexableLayout.postDelayed(new Runnable() {
@Override
public void run() {
gpsCity.get(0).setName("杭州市");
gpsHeaderAdapter.notifyDataSetChanged();
}
}, 3000);
// 搜索Demo
// initSearch();
}
private List iniyGPSCityDatas() {
List list = new ArrayList<>();
list.add(new CityEntity("定位中..."));
return list;
}
private List initDatas() {
List list = new ArrayList<>();
List cityStrings = Arrays.asList(getResources().getStringArray(R.array.city_array));
for (String item : cityStrings) {
CityEntity cityEntity = new CityEntity();
cityEntity.setName(item);
list.add(cityEntity);
}
return list;
}
private List iniyHotCityDatas() {
List list = new ArrayList<>();
list.add(new CityEntity("杭州市"));
list.add(new CityEntity("北京市"));
list.add(new CityEntity("上海市"));
list.add(new CityEntity("广州市"));
return list;
}
}
package com.mine.moviedemo.entity;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.mine.moviedemo.R;
import me.yokeyword.indexablerv.IndexableAdapter;
/** * Created by YoKey on 16/10/7. */
public class CityAdapter extends IndexableAdapter<CityEntity> {
private LayoutInflater mInflater;
public CityAdapter(Context context) {
mInflater = LayoutInflater.from(context);
}
@Override
public RecyclerView.ViewHolder onCreateTitleViewHolder(ViewGroup parent) {
View view = mInflater.inflate(R.layout.item_index_city, parent, false);
return new IndexVH(view);
}
@Override
public RecyclerView.ViewHolder onCreateContentViewHolder(ViewGroup parent) {
View view = mInflater.inflate(R.layout.item_city, parent, false);
return new ContentVH(view);
}
@Override
public void onBindTitleViewHolder(RecyclerView.ViewHolder holder, String indexTitle) {
IndexVH vh = (IndexVH) holder;
vh.tv.setText(indexTitle);
}
@Override
public void onBindContentViewHolder(RecyclerView.ViewHolder holder, CityEntity entity) {
ContentVH vh = (ContentVH) holder;
vh.tv.setText(entity.getName());
}
private class IndexVH extends RecyclerView.ViewHolder {
TextView tv;
public IndexVH(View itemView) {
super(itemView);
tv = (TextView) itemView.findViewById(R.id.tv_index);
}
}
private class ContentVH extends RecyclerView.ViewHolder {
TextView tv;
public ContentVH(View itemView) {
super(itemView);
tv = (TextView) itemView.findViewById(R.id.tv_name);
}
}
}
package com.mine.moviedemo.entity;
import me.yokeyword.indexablerv.IndexableEntity;
/** * Created by a on 2017/4/14. */
public class CityEntity implements IndexableEntity {
private long id;
private String name;
private String pinyin;
public CityEntity() {
}
public CityEntity(String name) {
this.name = name;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPinyin() {
return pinyin;
}
public void setPinyin(String pinyin) {
this.pinyin = pinyin;
}
@Override
public String getFieldIndexBy() {
return name;
}
@Override
public void setFieldIndexBy(String indexByField) {
this.name = indexByField;
}
@Override
public void setFieldPinyinIndexBy(String pinyin) {
this.pinyin = pinyin;
}
}
将开发中常用的RecyclerView的各种需求封装进库。
并且adapter支持数据管理,Header与Footer添加,加载更多。没有更多。加载错误
android图片轮播效果,RollViewPager的简单使用
RollViewPager的github
另一个轮播图Android广告图片轮播控件,支持无限循环和多种主题,可以灵活设置轮播样式、动画、轮播和切换时间、位置、图片加载框架等!
导入第三方的moudle时,最好先把三方的demo先导入一次,导入demo时,修改所有的(项目的gradle和moudle的gradle都要改)
‘compileSdkVersion 25
buildToolsVersion “25.0.3”’
然后修改项目的gradle目录下的两个文件,用本地文件去替换他们
这样就可以运行这个demo了
运行无误后,把这个改装后的moudle导入自己的项目即可,记得
’ compile project(‘:banner’)’,
这是还可能有错误,就需要对照原demo中的gradle文件,去添加一些代码
"1.0" encoding="utf-8"?>
.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/refresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
"match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
★ <com.jude.rollviewpager.RollPagerView
android:id="@+id/rollPager"
android:layout_width="match_parent"
android:layout_height="180dp"
app:rollviewpager_play_delay="3000"/>
"match_parent"
android:layout_height="match_parent"
android:text="@string/content"/>
.support.v4.widget.NestedScrollView>
.support.v4.widget.SwipeRefreshLayout>
package com.mine.moviedemo.fragment;
import android.graphics.Color;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.Toast;
import com.jude.rollviewpager.RollPagerView;
import com.jude.rollviewpager.adapter.StaticPagerAdapter;
import com.jude.rollviewpager.hintview.ColorPointHintView;
import com.mine.moviedemo.R;
import com.mine.moviedemo.base.BaseFragment;
/** * Created by a on 2017/4/13. */
public class FragmentHome extends BaseFragment implements SwipeRefreshLayout.OnRefreshListener {
private SwipeRefreshLayout mRefresh;
private View view;
private RollPagerView mRollViewPager;
@Override
protected void initView(View view) {
this.view = view;
mRefresh = (SwipeRefreshLayout) view.findViewById(R.id.refresh);
mRefresh.setOnRefreshListener(this);
mRollViewPager = (RollPagerView) view.findViewById(R.id.rollPager);
//设置播放时间间隔
mRollViewPager.setPlayDelay(1000);
//设置透明度
mRollViewPager.setAnimationDurtion(500);
//设置适配器
mRollViewPager.setAdapter(new TestNormalAdapter());
//设置指示器(顺序依次)
//自定义指示器图片
//设置圆点指示器颜色
//设置文字指示器
//隐藏指示器
//mRollViewPager.setHintView(new IconHintView(this, R.drawable.point_focus, R.drawable.point_normal));
mRollViewPager.setHintView(new ColorPointHintView(getContext(), Color.YELLOW, Color.WHITE));
//mRollViewPager.setHintView(new TextHintView(this));
//mRollViewPager.setHintView(null);
}
private class TestNormalAdapter extends StaticPagerAdapter {
private int[] imgs = {
R.mipmap.img1,
R.mipmap.img2,
R.mipmap.img3,
};
@Override
public View getView(ViewGroup container, int position) {
ImageView view = new ImageView(container.getContext());
view.setImageResource(imgs[position]);
view.setScaleType(ImageView.ScaleType.CENTER_CROP);
view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
return view;
}
@Override
public int getCount() {
return imgs.length;
}
}
@Override
protected int getLayoutId() {
return R.layout.fragment_home;
}
@Override
public void onRefresh() {
Toast.makeText(getContext(), "开始刷新", Toast.LENGTH_SHORT).show();
view.postDelayed(new Runnable() {
@Override
public void run() {
Toast.makeText(getContext(), "开始完毕", Toast.LENGTH_SHORT).show();
mRefresh.setRefreshing(false);
}
}, 1500);
}
}