0
在我的片段我有一個TextView下面有兩個按鈕。 我需要實現一個OnTouchListener做兩件事情:區分兩個手指旋轉和簡單的水龍頭
- 當我轉動我的兩個手指中,TextView的將旋轉
- 當我敲擊的TextView,按鈕下方被稱爲
現在它不起作用,但我找不到更好的解決方案。
XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_centerInParent="true"
tools:context="com.fjord.yalc.MainActivity"
android:id="@+id/player_fragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="@+id/buttonUp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@android:color/transparent"/>
<Button
android:id="@+id/buttonDown"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@android:color/transparent"/>
</LinearLayout>
<com.fjord.yalc.AutoResizeTextView
android:id="@+id/player"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:maxLines="1"
android:text="@string/normal_start"
android:textAppearance="@android:style/TextAppearance.DeviceDefault.DialogWindowTitle"
android:textColor="@color/colorLightGray"
android:textSize="300sp"
android:textStyle="bold"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
JAVA:
Btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
player.setText(String.valueOf(++life));
}
});
mRotationDetector = new RotationGestureDetector(this);
TV.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
int maskedAction = event.getActionMasked();
switch (maskedAction) {
case MotionEvent.ACTION_DOWN: {
return false;
}
case MotionEvent.ACTION_OUTSIDE: {
return false;
}
case MotionEvent.ACTION_MOVE: {
mRotationDetector.onTouchEvent(event);
break;
}
}
return true;
}
});
給自己上回的percistence拍拍 –