运行效果,可见上下页样式
demo链接:https://download.csdn.net/download/meixi_android/11045703
实现方法
首先添加必要依赖
implementation ('com.android.support:recyclerview-v7:27.0.2'){force = true
}
implementation ('com.android.support:cardview-v7:27.0.2'){force = true
}
implementation 'com.github.bumptech.glide:glide:3.6.1'
3、activity代码
public class MainActivity extends AppCompatActivity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);BannerLayout recyclerBanner = findViewById(R.id.recycler);List<String> list = new ArrayList<>();list.add("http://ww1.sinaimg.cn/large/b7cd25cagw1f55lgujsvuj20qo0z1n2o.jpg");list.add("http://b-ssl.duitang.com/uploads/item/201802/13/20180213092931_vlmdh.jpg");list.add("http://p2.qhimgs4.com/t010eb5908d6f28cf14.jpg");list.add("http://b-ssl.duitang.com/uploads/item/201802/13/20180213124050_gkhxt.jpg");list.add("http://dingyue.nosdn.127.net/3tqSsnfhfRRea6kZVlS0reiWcPFx9SR1jJ=cHkyEJLREO1530066845542compressflag.jpg");list.add("http://b-ssl.duitang.com/uploads/item/201802/13/20180213123947_cdkha.jpg");WebBannerAdapter webBannerAdapter=new WebBannerAdapter(this,list);webBannerAdapter.setOnBannerItemClickListener(new BannerLayout.OnBannerItemClickListener() {@Overridepublic void onItemClick(int position) {Toast.makeText(MainActivity.this, "点击了第 " + position+" 项", Toast.LENGTH_SHORT).show();}});recyclerBanner.setAdapter(webBannerAdapter);}
}
adapter类
public class WebBannerAdapter extends RecyclerView.Adapter<WebBannerAdapter.MzViewHolder> {private Context context;private List<String> urlList;private BannerLayout.OnBannerItemClickListener onBannerItemClickListener;public WebBannerAdapter(Context context, List<String> urlList) {this.context = context;this.urlList = urlList;}public void setOnBannerItemClickListener(BannerLayout.OnBannerItemClickListener onBannerItemClickListener) {this.onBannerItemClickListener = onBannerItemClickListener;}@Overridepublic WebBannerAdapter.MzViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {return new MzViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_image, parent, false));}@Overridepublic void onBindViewHolder(WebBannerAdapter.MzViewHolder holder, final int position) {if (urlList == null || urlList.isEmpty())return;final int P = position % urlList.size();String url = urlList.get(P);ImageView img = (ImageView) holder.imageView;Glide.with(context).load(url).into(img);holder.textView.setText(urlList.get(position));img.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {if (onBannerItemClickListener != null) {onBannerItemClickListener.onItemClick(P);}}});}@Overridepublic int getItemCount() {if (urlList != null) {return urlList.size();}return 0;}class MzViewHolder extends RecyclerView.ViewHolder {ImageView imageView;TextView textView;MzViewHolder(View itemView) {super(itemView);imageView = (ImageView) itemView.findViewById(R.id.image);textView = (TextView)itemView.findViewById(R.id.itemte);}}}
item_image.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"android:layout_width="250dp"android:layout_height="100dp"app:cardCornerRadius="5dp"><ImageViewandroid:id="@+id/image"android:layout_width="match_parent"android:layout_height="match_parent"android:scaleType="fitXY"/><TextViewandroid:id="@+id/itemte"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="aaa"/>
</android.support.v7.widget.CardView>
方法二:
圆角代码
Glide.with(context).load(entry.getBannerPath()).apply(new RequestOptions().diskCacheStrategy(DiskCacheStrategy.ALL).placeholder(R.color.white).transforms(new CenterCrop(), new RoundedCorners((int) 14))).into((ImageView) imageView);
实现效果
demo云盘链接:https://pan.baidu.com/s/1dJuZIhy5Lub_VE48e5JFuw
在线回复密码bug交流:扣1085220040