当前位置:网站首页>The best implementation of horizontal listview -- recycleview
The best implementation of horizontal listview -- recycleview
2022-07-28 18:02:00 【Two dollars and three dollars】
Reprint with reference to :http://blog.csdn.net/sange77/article/details/73753037
The other day , Write a horizontal list , I think it will be vertical at ordinary times listview Do it sideways , It's troublesome . later , Find out RecycleView This product can realize , The experience effect is also very good !
## See the effect 
## Code up
- gradle I quote
compile 'com.android.support:recyclerview-v7:26.0.0-alpha1'
- Activity
public class CustomViewActivity extends Activity {
private RecyclerView recyclerView; private MyRecyclerViewAdapter mAdapter = new MyRecyclerViewAdapter(); @Override protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.activity_custom_view); initView(); } private void initView() {
recyclerView = (RecyclerView) findViewById(R.id.rv_custom_view); recyclerView.setAdapter(mAdapter); LinearLayoutManager llm = new LinearLayoutManager(this); llm.setOrientation(LinearLayoutManager.HORIZONTAL);// Set to a horizontal layout recyclerView.setLayoutManager(llm); recyclerView.addItemDecoration(new DividerItemDecoration(this,DividerItemDecoration.HORIZONTAL));// Set the split line } Be careful :LinearLayoutManager.HORIZONTAL Want to be with DividerItemDecoration.HORIZONTAL Keep it up all the time , Will have a normal split line effect
- Activity XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center_horizontal">
<android.support.v7.widget.RecyclerView android:id="@+id/rv_custom_view" android:layout_width="match_parent" android:layout_height="wrap_content"/>
</LinearLayout>
- MyRecyclerViewAdapter
public class MyRecyclerViewAdapter extends RecyclerView.Adapter<MyRecyclerViewAdapter.MyViewHolder> {
@Override public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_recyclerview,parent,false); return new MyViewHolder(view); } @Override public void onBindViewHolder(MyViewHolder holder, int position) {
} @Override public int getItemCount() {
return 9; } class MyViewHolder extends RecyclerView.ViewHolder{
public MyViewHolder(View itemView) {
super(itemView); } } } - item_recyclerview
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text=" Test text " android:textSize="18sp" android:textStyle="bold"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text=" This is the details ....."/>
</LinearLayout>
**item Do you want to adapt to full screen Control size , The main change is item_recyclerview.xml Mid root layout android:layout_width and android:layout_height **
ok, That's all. !
Reprint with reference to :http://blog.csdn.net/sange77/article/details/73753037
边栏推荐
- 公众号和视频号互相绑定带来的功能
- 关于localtion 下的root和alias的区别
- [C language note sharing] - dynamic memory management malloc, free, calloc, realloc, flexible array
- Digital filter (VI) -- design FIR filter
- Leetcode systematic question brushing (V) -- dynamic programming
- 个人制作:AD库、元件库、封装库及3D模型,免费
- Connect other computers to local MySQL
- Leetcode systematic question brushing (II) -- greed, backtracking, recursion
- 3D point cloud processing series - ---- PCA
- 概率函数P(x)、概率分布函数F(x)与概率密度函数f(x)的区别
猜你喜欢
随机推荐
视频号7天销售额超百万
IDEA报错Error running ‘Application‘ Command line is too long解决方案
Digital filter (I) -- basic structure and matlab implementation of IIR and fir
Electrotechnics self study notes 1.22
视频号更像是2.0版的公众号
公众号和视频号互相绑定带来的功能
1.4-dos
Prize essay solicitation | the 2022 cloud native programming challenge draft activity is open!
Tips -- understanding of the physical meaning of convolution
关于图片的像素、分辨率、尺寸问题的解答,以及显示器的显示大小。
3D point cloud processing series - ---- PCA
Electrotechnics Volume II self study notes 1.23
2022 IDEA (学生邮箱认证)安装使用教程以及基础配置教程
【干货】如何建立支持和产品之间的密切关系?
Openmv (VI) -- STM32 realizes object recognition and handwritten digit recognition
The difference between probability function p (x), probability distribution function f (x) and probability density function f (x)
[unity] timeline learning notes (VII): Custom clip
分支与循环语句
Branch and loop statements
Image processing code sorting








