ImageView 不调度 TouchEvent

发布于 2024-12-11 00:54:28 字数 1604 浏览 0 评论 0原文

当我触摸屏幕的左侧或右侧时,我想更改 ImageView 中的图像(从 Web url 获取的图像)。我尝试使用 TouchListener,但收到有关dispatchTouchEvent 的错误。

使用图库视图不是解决方案,因为我希望图像全屏显示。

这是我使用的代码。

 public class Prova4Activity extends Activity implements OnTouchListener {
/** Called when the activity is first created. */
ImageView image;
Bitmap trash = loadImageFromUrl("http://www.televideo.rai.it/televideo/pub/tt4web/Nazionale/16_9_page-100.6.png");
ImageView imgpag;
@Override
public boolean onTouch(View v, MotionEvent event) {
    if(event.getAction() == MotionEvent.EDGE_RIGHT){
        trash.recycle();
         trash = null;
         trash = loadImageFromUrl("http://www.televideo.rai.it/televideo/pub/tt4web/Nazionale/16_9_page-100.6.png");
         image.setImageBitmap(trash);

         }else if(event.getAction() == MotionEvent.EDGE_LEFT){
             trash.recycle();
             trash = null;
             trash = loadImageFromUrl("http://www.televideo.rai.it/televideo/pub/tt4web/Nazionale/16_9_page-100.5.png");
             imgpag.setImageBitmap(trash);

         }
    imgpag.setScaleType(ScaleType.FIT_XY);

    return false;
}
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    imgpag = (ImageView)findViewById (R.id.imgpag); 
    imgpag.setImageBitmap(trash);
    imgpag.setOnTouchListener(this);

}
}

在 logcat 中我多次看到以下消息:

Key dispatching timed out sending to com.namemyapp Current state {{null Window{439f0e10 com.namemyapp Continuing to wait for key to be dispatched

I want to change the image (that I get from a web url) in my ImageView when I touch the left or right of the screen. I tried using a TouchListener but I get an error about dispatchTouchEvent.

Using a gallery view is not the solution because I want the images displayed in full screen.

This is the code I use.

 public class Prova4Activity extends Activity implements OnTouchListener {
/** Called when the activity is first created. */
ImageView image;
Bitmap trash = loadImageFromUrl("http://www.televideo.rai.it/televideo/pub/tt4web/Nazionale/16_9_page-100.6.png");
ImageView imgpag;
@Override
public boolean onTouch(View v, MotionEvent event) {
    if(event.getAction() == MotionEvent.EDGE_RIGHT){
        trash.recycle();
         trash = null;
         trash = loadImageFromUrl("http://www.televideo.rai.it/televideo/pub/tt4web/Nazionale/16_9_page-100.6.png");
         image.setImageBitmap(trash);

         }else if(event.getAction() == MotionEvent.EDGE_LEFT){
             trash.recycle();
             trash = null;
             trash = loadImageFromUrl("http://www.televideo.rai.it/televideo/pub/tt4web/Nazionale/16_9_page-100.5.png");
             imgpag.setImageBitmap(trash);

         }
    imgpag.setScaleType(ScaleType.FIT_XY);

    return false;
}
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    imgpag = (ImageView)findViewById (R.id.imgpag); 
    imgpag.setImageBitmap(trash);
    imgpag.setOnTouchListener(this);

}
}

In logcat I see the following message many times:

Key dispatching timed out sending to com.namemyapp Current state {{null Window{439f0e10 com.namemyapp Continuing to wait for key to be dispatched

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文