2017-05-14 46 views
0

中的MaterialRippleLayout我正在使用MaterialRippleLayout来为我的应用中的纹波效果生成图片。在我的活动中,我实现了点击图片上的代码,它将开始新的活动,没有MaterialRippleLayout我的代码工作正常。但与MaterialRippleLayout点击不起作用。波纹管是我的代码。onclick不适用于Android

<com.balysv.materialripple.MaterialRippleLayout 
        android:id="@+id/ripple" 
        android:layout_centerInParent="true" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        app:mrl_rippleOverlay="true" 
        app:mrl_rippleColor="#000" 
        app:mrl_rippleAlpha="0.2" 
        app:mrl_rippleDimension="10dp" 
        app:mrl_rippleHover="true" 
        app:mrl_rippleRoundedCorners="10dp" 
        app:mrl_rippleInAdapter="false" 
        app:mrl_rippleDuration="350" 
        app:mrl_rippleFadeDuration="75" 
        app:mrl_rippleDelayClick="false" 
        app:mrl_rippleBackground="#FFF" 
        app:mrl_ripplePersistent="true"> 

        <ImageView 
         android:id="@+id/thumbnail" 
         android:layout_width="match_parent" 
         android:layout_height="160dp" 
         android:background="?attr/selectableItemBackgroundBorderless" 
         android:scaleType="fitXY" /> 

       </com.balysv.materialripple.MaterialRippleLayout> 

以下是我的依赖

compile 'com.balysv:material-ripple:1.0.2' 

我在适配器的Java代码

public class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{ 
     public TextView title, count; 
     public ImageView thumbnail; 

     ArrayList<Catagory> CatagoryList = new ArrayList<Catagory>(); 
     Context mContext; 

     public MyViewHolder(View view , Context mContext, ArrayList<Catagory> CatagoryList) { 
      super(view); 
      this.CatagoryList = CatagoryList; 
      this.mContext = mContext; 
      view.setOnClickListener(this); 
      title = (TextView) view.findViewById(R.id.title); 
      count = (TextView) view.findViewById(R.id.count); 
      thumbnail = (ImageView) view.findViewById(R.id.thumbnail); 
     } 

     @Override 
     public void onClick(View view) { 
      int position = getAdapterPosition(); 
      Catagory CatagoryList = this.CatagoryList.get(position); 
      Intent intent = new Intent(this.mContext, CatagoryVendListActivity.class); 
      intent.putExtra("CatId", CatagoryList.getVendId()); 
      intent.putExtra("CatName", CatagoryList.getName()); 
      this.mContext.startActivity(intent); 


     } 
    } 

请评论,如果您有任何疑问。

+0

你可以发布你的'onClick'的java代码吗? – Kaushal28

+0

我已经在onClick上添加了java代码 –

+0

这个id的初始化在哪里:'ripple'视图? – Kaushal28

回答

1

从库中的文档,可以初始化纹波观点如下:

MaterialRippleLayout.on(view) 
     .rippleColor(Color.BLACK) 
     .create(); 

哪里view您的看法,您要设置这个效果到。

我们设置onClickListener,使用下面的代码:

findViewById(R.id.ripple).setOnClickListener(new View.OnClickListener() { 
    @Override public void onClick(View v) { 
     //handle click here. 
    } 
}); 
+0

这是不是我看到的答案,但你给我的想法。我添加mRipple =(MaterialRippleLayout)view.findViewById(R.id.ripple); MaterialRippleLayout.on(mRipple).create(); mRipple.setOnClickListener(this ); –

+0

现在工作吗? – Kaushal28

+0

是的,它工作。发布回答 –

0

那些谁正在寻找相同的解决方案。下面是我的回答

private MaterialRippleLayout mRipple; 

public class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{ 
     public TextView title, count; 
     public ImageView thumbnail; 

     ArrayList<Catagory> CatagoryList = new ArrayList<Catagory>(); 
     Context mContext; 

     public MyViewHolder(View view , Context mContext, ArrayList<Catagory> CatagoryList) { 
      super(view); 
      this.CatagoryList = CatagoryList; 
      this.mContext = mContext; 
      //view.setOnClickListener(this); 
      title = (TextView) view.findViewById(R.id.title); 
      count = (TextView) view.findViewById(R.id.count); 
      thumbnail = (ImageView) view.findViewById(R.id.thumbnail); 
      mRipple = (MaterialRippleLayout) view.findViewById(R.id.ripple); 
      MaterialRippleLayout.on(mRipple).create(); 
      mRipple.setOnClickListener(this); 
     } 

     @Override 
     public void onClick(View view) { 
      int position = getAdapterPosition(); 
      Catagory CatagoryList = this.CatagoryList.get(position); 
      Intent intent = new Intent(this.mContext, CatagoryVendListActivity.class); 
      intent.putExtra("CatId", CatagoryList.getVendId()); 
      intent.putExtra("CatName", CatagoryList.getName()); 
      this.mContext.startActivity(intent); 


     } 
    }