【发布时间】:2017-08-28 08:14:38
【问题描述】:
如何设置双击来点赞 android 中的图片。(如 instagram 照片)
我这里有以下代码:
final ImageView photo_show = (ImageView) findViewById(R.id.imgv_photo);// this is main image
final ImageView imgv_like_photo = (ImageView) findViewById(R.id.imgv__like_photo);// this is heart image
imgv_musics_activity_like_photo.setVisibility(View.GONE);
photo_show.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
photo_show.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
like(imgv_musics_activity_like_photo);
}
});
}
});
public void like(View view) {
TranslateAnimation animate = new TranslateAnimation(0, view.getWidth(), 0, 0);
animate.setDuration(500);
animate.setFillAfter(true);
view.startAnimation(animate);
view.setVisibility(View.VISIBLE);
}
还有xml:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<ImageView
android:id="@+id/imgv_photo"
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_centerHorizontal="true"
android:contentDescription="@string/image_photo"
tools:src="@drawable/no_photo" />
<ImageView
android:id="@+id/imgv_like_photo"
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_centerHorizontal="true"
android:contentDescription="@string/image_photo"
android:src="@drawable/ic_like" />
</RelativeLayout>
双击时,此代码仅在图像上显示心形。例如,我想在 2 秒后隐藏。 各位大神能给个方法吗?
【问题讨论】:
-
此链接可能对您有所帮助stackoverflow.com/questions/5191456/…