我正在使用选择器和触摸侦听器来设置片段中MotionEvent.ACTION_DOWN上按下的按钮。但是当调用Context Menu时,按钮变得不被按下。这个onTouch方法在片段内:
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
switch (view.getId()) {
case R.id.buttonRow:
if (!buttonRow.isPressed()) {
buttonRow.setPressed(true);
buttonGrid.setPressed(false);
setLinearManager();
}
break;
case R.id.buttonGrid:
if (!buttonGrid.isPressed()) {
buttonGrid.setPressed(true);
buttonRow.setPressed(false);
setGridManager();
}
break;
}
}
return true;
}
片段xml,其中按钮位于:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.boss.lesson5.fragments.RecyclerViewFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:orientation="horizontal">
<ImageButton
android:id="@+id/buttonRow"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="@drawable/button_effect"
android:padding="15dp"
android:scaleType="centerInside"
android:src="@drawable/row" />
<ImageButton
android:id="@+id/buttonGrid"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="@drawable/button_effect"
android:padding="15dp"
android:scaleType="centerInside"
android:src="@drawable/grid" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="60dp" />
答案 0 :(得分:1)
尝试使用此模型:
<wt-wish-added-promised-info one-time-binding="false" ...></wt-wish-added-promised-info>