我想在我的應用程序中實現OnTouchListener。我想:Android OnTouchListener
- 當我觸摸屏幕時,我需要顯示或隱藏一些動作:這裏的時候,我接觸的ImageView,顯示哪些處理措施
我的佈局中的LinearLayout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rl_af"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000">
<ImageView
android:id="@+id/ivaf"
android:layout_width="match_parent"
android:layout_height="400dp"
android:layout_centerInParent="true" />
<LinearLayout
android:id="@+id/llaffbtn"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#000000"
android:src="@drawable/ic_file_download_white_24dp" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#000000"
android:src="@drawable/ic_share_white_24dp" />
</LinearLayout>
,什麼我想在我的java類:
img = (ImageView) findViewById(R.id.ivaf);
rl = (RelativeLayout) findViewById(R.id.rl_af);
affBtn = (LinearLayout) findViewById(R.id.llaffbtn);
rl.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
affBtn.setVisibility(View.VISIBLE);
}
if (event.getAction() == MotionEvent.ACTION_UP) {
affBtn.setVisibility(View.INVISIBLE);
}
return false;
}
});
您遇到什麼問題? – Kuffs
此代碼無法使用。當我觸摸imageView的linearlayout,我把其他兩個按鈕不會消失 –
如果你只是想隱藏'linearLayout'你爲什麼不使用'onClickListener'? – Wizard