91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

RecyclerView實現水波紋點擊效果

發布時間:2020-09-24 15:00:30 來源:腳本之家 閱讀:322 作者:REIGE 欄目:移動開發

本文實例為大家分享了RecyclerView實現水波紋點擊效果的具體代碼,供大家參考,具體內容如下

效果圖

RecyclerView實現水波紋點擊效果

item.xml

這里就是主要設置background為我們后面寫的一個selector

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:background="@drawable/recycler_item_selector"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
 <TextView
  android:id="@+id/textView"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:gravity="center"
  android:textSize="40sp"
  android:text="aaaa"/>
</LinearLayout>

drawable-v21/recycler_item_selector.xml (v21版本以上)

<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
  android:color="@color/colorPrimary">
 <item android:drawable="@color/write"/>
</ripple>

drawable/recycler_item_selector.xml (v21版本以下的沒有水波紋效果)

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
 <item android:drawable="@color/colorPrimary" android:state_pressed="true"/>
 <item android:drawable="@color/colorPrimary" android:state_focused="true"/>
 <item android:drawable="@color/write"/>
</selector>

接下來是MyAdapter

public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {


 private OnRvItemClick mOnRvItemClick;
 private Context mContext;
 String[] strings;

 public MyAdapter(Context ctx, String[] strings, OnRvItemClick onRvItemClick) {
  mContext = ctx;
  this.mOnRvItemClick = onRvItemClick;
  this.strings = strings;
 }

 @Override
 public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
  View view = LayoutInflater.from(mContext).inflate(R.layout.item, parent, false);
  return new ViewHolder(view);
 }

 @Override
 public void onBindViewHolder(ViewHolder holder, int position) {
  holder.setData(position);
 }

 @Override
 public int getItemCount() {
  return 20;
 }


 public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
  @BindView(R.id.textView)
  TextView textView;

  public ViewHolder(View itemView) {
   super(itemView);
   ButterKnife.bind(this,itemView);
   itemView.setOnClickListener(this);
  }

  public void setData(int position) {

   textView.setText("position" + position);
  }

  @Override
  public void onClick(View view) {
   if (mOnRvItemClick != null)
    mOnRvItemClick.onItemClick(view, getAdapterPosition());
  }

 }


 /**
  * item點擊接口
  */
 public interface OnRvItemClick {
  void onItemClick(View v, int position);
 }
}

MainActivity

public class MainActivity extends AppCompatActivity {

 @BindView(R.id.RecyclerView)
 RecyclerView mRecyclerView;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  ButterKnife.bind(this);
  MyAdapter myAdapter = new MyAdapter(this, null, new MyAdapter.OnRvItemClick() {
   @Override
   public void onItemClick(View v, int position) {
    Toast.makeText(getApplicationContext(), "click" + position, Toast.LENGTH_SHORT)
      .show();
   }
  });
  mRecyclerView.setLayoutManager(new LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false));

  mRecyclerView.setAdapter(myAdapter);
 }
}

github :RecyclerView水波紋效果

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持億速云。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

广平县| 沈丘县| 锦州市| 丹阳市| 泸西县| 安图县| 杭锦后旗| 杂多县| 闻喜县| 灌南县| 汾阳市| 镇原县| 古丈县| 东丰县| 呈贡县| 胶南市| 彭水| 冷水江市| 石嘴山市| 安龙县| 旅游| 永吉县| 邹平县| 阳西县| 城步| 精河县| 麻栗坡县| 顺平县| 观塘区| 富锦市| 龙江县| 宁安市| 顺义区| 凤冈县| 黄梅县| 崇仁县| 黎城县| 昭苏县| 临朐县| 临澧县| 尼勒克县|