gpt4 book ai didi

Android ImageView 通过 ImageView OnTouchListener

转载 作者:太空狗 更新时间:2023-10-29 16:38:21 26 4
gpt4 key购买 nike

enter image description here

我有两个 ImageView ,它们看起来像这样。我想将 TouchListener 添加到 imageview1。但听众无法正常工作。我正在将 imageview2 添加到

 android:focusable="false"

但不能再工作了

最佳答案

试试这个。即使您单击 imageview2,它对我也能正常工作。 MainActivity onCreate():

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

ImageView imageView1 = (ImageView) findViewById(R.id.imageview1);
imageView1.setOnTouchListener(new OnTouchListener() {

@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
Log.i("imageviewandontouchlistener", "imageView1 onTouch");
return false;
}
});
}

在您的布局 XML 中:

<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<ImageView
android:id="@+id/imageview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/image1"/>

<ImageView
android:id="@+id/imageview2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/image2" />
</FrameLayout>

关于Android ImageView 通过 ImageView OnTouchListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22613450/

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