1
CODE:onTouchListener不工作
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,onTouchListener爲TextView寫了什麼,mRotate_imageActivity不起作用。
問題:我該如何讓onTouchListener工作?
我在哪裏添加它?請你讓我知道嗎? – touchingtwist
@touchingtwist我更新了我的回答 –
謝謝艾哈邁德Hegazy – touchingtwist