2017-05-14 111 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); 


     } 
    }