日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

android开发 RecyclerView 瀑布列表布局

發(fā)布時(shí)間:2024/4/15 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android开发 RecyclerView 瀑布列表布局 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
android開(kāi)發(fā) RecyclerView 瀑布列表布局

1.寫(xiě)一個(gè)內(nèi)容的自定義小布局:

<?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"android:layout_margin="10dp"><ImageViewandroid:id="@+id/waterfall_Image"android:layout_width="wrap_content"android:layout_height="wrap_content"android:src="@drawable/ace"/><TextViewandroid:id="@+id/waterfall_Name_TextView"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="這里顯示名稱(chēng)"android:textSize="15sp"android:textColor="@color/colorBlack"android:layout_gravity="center_horizontal"/><TextViewandroid:id="@+id/waterfall_contents_TextView"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="這里顯示內(nèi)容"android:textSize="10sp"android:textColor="@color/colorblue"/></LinearLayout>



布局預(yù)覽:


寫(xiě)一個(gè)內(nèi)容適配器class:

package com.example.lenovo.myrecyclerview.RecyclerViewToolkit;import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; import com.example.lenovo.myrecyclerview.R;import java.util.List;/*** Created by lenovo on 2018/5/2.*/public class ListAdapter extends RecyclerView.Adapter<ListAdapter.ViewHolder> {private List<ListData> mDataList;static class ViewHolder extends RecyclerView.ViewHolder{ImageView imageAvatar;TextView nameText;TextView contentsText;public ViewHolder(View itemView) {super(itemView);//注意這里可能需要import com.example.lenovo.myrecyclerview.R; 才能使用R.idimageAvatar = (ImageView)itemView.findViewById(R.id.waterfall_Image);nameText =(TextView) itemView.findViewById(R.id.waterfall_Name_TextView);contentsText = (TextView)itemView.findViewById(R.id.waterfall_contents_TextView);}}public ListAdapter(List<ListData> listDatas){mDataList = listDatas;}@Overridepublic ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.waterfall_list_view,parent,false);ViewHolder holder = new ViewHolder(view);return holder;}@Overridepublic void onBindViewHolder(ViewHolder holder, int position) {ListData listData = mDataList.get(position);holder.imageAvatar.setImageResource(listData.getImageView());holder.nameText.setText(listData.getNameText());holder.contentsText.setText(listData.getContentsText());}@Overridepublic int getItemCount() {return mDataList.size();} }


寫(xiě)一個(gè)RecyclerView 瀑布列表布局活動(dòng)class:



package com.example.lenovo.myrecyclerview;import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.StaggeredGridLayoutManager;import com.example.lenovo.myrecyclerview.RecyclerViewToolkit.ListAdapter; import com.example.lenovo.myrecyclerview.RecyclerViewToolkit.ListData;import java.util.ArrayList; import java.util.List;public class RecyclerViewActivity extends AppCompatActivity {private List<ListData> listDatas = new ArrayList<>(); //創(chuàng)建數(shù)據(jù)list@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_recycler_view);addingData(); //導(dǎo)入數(shù)據(jù)RecyclerView recyclerView = (RecyclerView)findViewById(R.id.RecyclerView);//在此處修改布局排列方向StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(3,StaggeredGridLayoutManager.VERTICAL);recyclerView.setLayoutManager(staggeredGridLayoutManager);ListAdapter listAdapter = new ListAdapter(listDatas); //創(chuàng)建適配器,并且導(dǎo)入數(shù)據(jù)listrecyclerView.setAdapter(listAdapter);//布局導(dǎo)入適配器}//添加數(shù)據(jù)public void addingData(){ListData ace = new ListData(R.drawable.ace,"ace", "波特卡斯·D·艾斯:" +"燒燒果實(shí)的前任能力者,綽號(hào)“火拳”,實(shí)力強(qiáng)大。");listDatas.add(ace); //以下省略.....}}

實(shí)現(xiàn)效果圖:


posted on 2018-05-03 17:17?觀心靜 閱讀(...) 評(píng)論(...) 編輯 收藏

轉(zhuǎn)載于:https://www.cnblogs.com/guanxinjing/p/9708629.html

總結(jié)

以上是生活随笔為你收集整理的android开发 RecyclerView 瀑布列表布局的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。