我在我的应用中使用MaterialRippleLayout
图片获取Ripple效果。在我的活动中,我在点击图片上实现了代码,它将启动新的活动,而MaterialRippleLayout
我的代码工作正常。但是MaterialRippleLayout
点击不起作用。吼叫是我的代码。
<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 :(得分: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.
}
});
答案 1 :(得分: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);
}
}