gpt4 book ai didi

android - onTouchListener 不工作

转载 作者:行者123 更新时间:2023-11-30 00:54:43 27 4
gpt4 key购买 nike

代码:

public class ImageActivity extends FragmentActivity {

ImageView mClickedImage;
PhotoViewAttacher mPhotoViewAttacher;
TextView mRotate_imageActivity;
private int BASEINT_ImageActivity;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_image);
Intent intent = getIntent();
final String string = (String) intent.getSerializableExtra("Clicked Image");
mClickedImage = (ImageView) findViewById(R.id.iv_clicked_image);
mRotate_imageActivity = (TextView) findViewById(R.id.tv_rotate_imageActivity);

mPhotoViewAttacher = new PhotoViewAttacher(mClickedImage);

Glide.with(getApplicationContext())
.load(string)
.fitCenter()
.into(mClickedImage);

mRotate_imageActivity.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
Glide.with(getApplicationContext())
.load(string)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.transform(new RotateHelper(getApplicationContext(), 90f))
.into(mClickedImage);

return true;
}
});
}
}

XML 代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.keepair.www.pinair.ImageActivity">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/rl_rotate_text">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tv_rotate_imageActivity"
android:text="@string/rotate"/>
</RelativeLayout>

<ImageView
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/iv_clicked_image"/>
</RelativeLayout>

正如您在上面看到的,我的 xml 代码表明 textview 在 imageview 上。他们被重叠。

但我认为,由于 photoviewattacher,为 TextView、mRotate_imageActivity 编写的 onTouchListener 不起作用。

问题:如何让 onTouchListener 工作?

最佳答案

在更改 ImageView 的图像后,您需要在 PhotoViewAttacher 中调用 update

// If you later call mImageView.setImageDrawable/setImageBitmap/setImageResource/etc then you just need to call
mAttacher.update();

在您的情况下,您可以将监听器附加到 Glide 以了解图像何时加载并在那里更新 PhotoViewAttacher

Glide.with(getActivity())
.load(args.getString(IMAGE_TO_SHOW))
.listener(new RequestListener<String, GlideDrawable>() {
@Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
return false;
}

@Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
mAttacher.update();
return false;
}
})
.into(imageView)

关于android - onTouchListener 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40378912/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com