国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Android > 正文

Android 實現(xiàn)當下最流行的吸頂效果

2019-12-12 03:13:43
字體:
來源:轉載
供稿:網(wǎng)友

開始逐漸領略到ItemDecoration的美~

今天讓我 使用 ItemDecoration 來完成 可推動的懸浮導航欄的效果,最終實現(xiàn)的效果如下圖:

具體實現(xiàn)步驟如下:

根據(jù)我前面的文章所講的RecyclerView的基本使用,我們先來完成基本的recyclerView

第一步:布局里寫一個RecyclerView

第二步:實例化

recyclerView = (RecyclerView) findViewById(R.id.recyclerView);

第三步:獲取所需的數(shù)據(jù) (這里我們來個真實點的情景,去聯(lián)網(wǎng)請求數(shù)據(jù))

//聯(lián)網(wǎng)獲取數(shù)據(jù)  getDataFromNet(); 
/** * 使用okhttpUtils進行聯(lián)網(wǎng)請求數(shù)據(jù) */  private void getDataFromNet() {  OkHttpUtils.  get()  .url(url)  .build()  .execute(new StringCallback() {   @Override   public void onError(okhttp3.Call call, Exception e, int id) {   Log.e("TAG", "聯(lián)網(wǎng)失敗" + e.getMessage());   }    @Override   public void onResponse(String response, int id) {   Log.e("TAG", "聯(lián)網(wǎng)成功==" + response);    //聯(lián)網(wǎng)成功后使用fastjson解析   processData(response);   }  });  }
/** * 使用fastjson進行解析 * * @param json */  private void processData(String json) {  //這里使用GsonFormat生成對應的bean類  JSONObject jsonObject = parseObject(json);   String data = jsonObject.getString("data");  JSONObject dataObj = JSON.parseObject(data);   String coming = dataObj.getString("coming");  List<WaitMVBean.DataBean.ComingBean> comingslist = parseArray(coming, WaitMVBean.DataBean.ComingBean.class);   //測試是否解析數(shù)據(jù)成功 // String strTest = comingslist.get(0).getCat(); // Log.e("TAG", strTest + "222");   //解析數(shù)據(jù)成功,設置適配器-->   }  }

第四步:解析數(shù)據(jù)成功后,創(chuàng)建并設置適配器,并傳遞相關數(shù)據(jù)

//解析數(shù)據(jù)成功,設置適配器  MyRecyclerAdapter adapter = new MyRecyclerAdapter( mContext,comingslist);  recyclerView.setAdapter(adapter);

適配器:

public class MyRecyclerAdapter extends RecyclerView.Adapter {  private final List<WaitMVBean.DataBean.ComingBean> comingslist;  private final Context mContext;  private final LayoutInflater mLayoutInflater;  public MyRecyclerAdapter(Context mContext, List<WaitMVBean.DataBean.ComingBean> comingslist) {  this.mContext = mContext;  this.comingslist = comingslist;  mLayoutInflater = LayoutInflater.from(mContext);  }  @Override  public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {  return new MyViewHolder(mLayoutInflater.inflate(R.layout.date_item, null));  }  @Override  public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {  MyViewHolder myholder = (MyViewHolder) holder;  myholder.setData(position);  }  @Override  public int getItemCount() {  return comingslist.size();  }  class MyViewHolder extends RecyclerView.ViewHolder {  private TextView mv_name;  private TextView mv_dec;  private TextView mv_date;  private ImageView imageView;  public MyViewHolder(View itemView) {  super(itemView);  mv_name = (TextView) itemView.findViewById(R.id.mv_name);  mv_dec = (TextView) itemView.findViewById(R.id.mv_dec);  mv_date = (TextView) itemView.findViewById(R.id.mv_date);  imageView = (ImageView) itemView.findViewById(R.id.image);  }  public void setData(int position) {  WaitMVBean.DataBean.ComingBean coming = comingslist.get(position);  String name = coming.getNm();  mv_name.setText(name);  String date = coming.getShowInfo();  mv_date.setText(date);  String dec = coming.getScm();  mv_dec.setText(dec);  //注:當你發(fā)下圖片無法打開是,做個字符串替換即可  String imagUrl = coming.getImg();  String newImagUrl = imagUrl.replaceAll("w.h", "50.80");   //使用Glide加載圖片  Glide.with(mContext)   .load(newImagUrl)   .into(imageView);  }  } }

item的布局:

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:background="#ffffff"  android:gravity="center_vertical"  android:orientation="horizontal">  <ImageView  android:id="@+id/image"  android:layout_width="70dp"  android:layout_height="110dp"  android:layout_marginBottom="5dp"  android:layout_marginLeft="10dp"  android:layout_marginRight="8dp"  android:layout_marginTop="5dp" />  <LinearLayout  android:layout_width="0dp"  android:layout_height="wrap_content"  android:layout_marginLeft="6dp"  android:layout_weight="1"  android:orientation="vertical">  <TextView  android:id="@+id/mv_name"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:text="神奇

主站蜘蛛池模板:
资中县|
开化县|
蕉岭县|
云和县|
永寿县|
嘉祥县|
荆州市|
九江县|
富宁县|
黎城县|
郎溪县|
乌兰县|
杭锦后旗|
建平县|
奉新县|
无为县|
永泰县|
扎鲁特旗|
多伦县|
南通市|
襄垣县|
托里县|
乐陵市|
革吉县|
和林格尔县|
晋江市|
定安县|
丰台区|
禄劝|
碌曲县|
芮城县|
和林格尔县|
安康市|
武功县|
亳州市|
阳信县|
广元市|
杂多县|
比如县|
平阴县|
密山市|