WebView webView = (WebView) rootView.findViewById(R.id.webView2);
final ConstraintLayout topBar = (ConstraintLayout) rootView.findViewById(R.id.topBar);
final ConstraintLayout BottomBar = (ConstraintLayout) rootView.findViewById(R.id.BottomBar);
webView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN:
return false;
case MotionEvent.ACTION_MOVE:{
return false;
}
case MotionEvent.ACTION_UP:
if(animState == false){
Animation animation = AnimationUtils.loadAnimation(getActivity(),R.anim.anim_document_web_view_top_bar_up);
Animation animation2 = AnimationUtils.loadAnimation(getActivity(),R.anim.anim_document_web_view_bottom_bar_down);
topBar.startAnimation(animation);
BottomBar.startAnimation(animation2);
animState = true;
} else{
Animation animation = AnimationUtils.loadAnimation(getActivity(),R.anim.anim_document_web_view_top_bar_down);
Animation animation2 = AnimationUtils.loadAnimation(getActivity(),R.anim.anim_document_web_view_bottom_bar_up);
topBar.startAnimation(animation);
BottomBar.startAnimation(animation2);
animState = false;
}
return true;
}
return false;
}
});
스위치 케이스에서 액션다운과 액션무브를 지우게 되면
다운과 무브가 그대로 작동되기 때문에 액션업이 작동되지 않는다.
액션 다운만 사용시 -> 액션업 return false;
액션 업만 사용시 -> 액션 다운, 액션 무브 return false;
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:focusable="true">
<WebView
android:id="@+id/webView2"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<androidx.constraintlayout.widget.ConstraintLayout
android:clickable="true"
android:id="@+id/topBar"
android:layout_width="match_parent"
android:layout_height="70dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:background="@drawable/document_web_view_round"
android:layout_width="match_parent"
android:layout_height="85dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent">
<ImageView
android:layout_marginTop="2.5dp"
android:id="@+id/btnClose2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="@drawable/document_back"
android:padding="15dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
<TextView
android:layout_marginTop="2.5dp"
android:layout_gravity="center"
android:id="@+id/title2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:textSize="20dp"
android:maxLength="30"
android:text="testTitle"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:clickable="true"
android:id="@+id/BottomBar"
android:layout_width="match_parent"
android:layout_height="70dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:background="@drawable/document_web_view_round"
android:layout_width="match_parent"
android:layout_height="85dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_marginTop="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingStart="10dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:gravity="center_horizontal">
<EditText
android:padding="15dp"
android:id="@+id/editNowPage2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:singleLine="true"
android:inputType="number"
android:background="@null"
android:textColorHint="@color/white"
android:textColor="@color/white"
android:textStyle="bold"
android:hint="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="/"
android:textSize="20dp"
android:textStyle="bold"
android:textColor="@color/white"/>
<TextView
android:paddingHorizontal="15dp"
android:id="@+id/txtTotalPage2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:textColor="@color/white"
android:textStyle="bold"
android:text="9999"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:gravity="center_horizontal">
<ImageView
android:id="@+id/btnPrevious2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/document_previous"
android:padding="15dp" />
<ImageView
android:id="@+id/btnForward2"
android:layout_marginStart="50dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/document_next"
android:padding="15dp" />
</LinearLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true">
<translate
android:fromYDelta="0%p"
android:toYDelta="20%p"
android:duration="800"
android:repeatCount="0" />
<!-- android:fromYDelta="0%p" : 시작 위치 -->
<!-- android:toYDelta="30%p" : 종료 위치 -->
<!-- android:duration="2000" : 동작 시간 -->
<!-- android:repeatCount="-1" : 반복횟수(-1은 무한반복) -->
<!-- android:fillAfter="true" : 애니메이션 종료 후 위치 원상복귀 여부 -->
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true">
<translate
android:fromYDelta="20%p"
android:toYDelta="0%p"
android:duration="800"
android:repeatCount="0" />
<!-- android:fromYDelta="0%p" : 시작 위치 -->
<!-- android:toYDelta="30%p" : 종료 위치 -->
<!-- android:duration="2000" : 동작 시간 -->
<!-- android:repeatCount="-1" : 반복횟수(-1은 무한반복) -->
<!-- android:fillAfter="true" : 애니메이션 종료 후 위치 원상복귀 여부(안먹으면 set안에 작성) -->
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true">
<translate
android:fromYDelta="0%p"
android:toYDelta="-20%p"
android:duration="800"
android:repeatCount="0" />
<!-- android:fromYDelta="0%p" : 시작 위치 -->
<!-- android:toYDelta="30%p" : 종료 위치 -->
<!-- android:duration="2000" : 동작 시간 -->
<!-- android:repeatCount="-1" : 반복횟수(-1은 무한반복) -->
<!-- android:fillAfter="true" : 애니메이션 종료 후 위치 원상복귀 여부 -->
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true">
<translate
android:fromYDelta="-20%p"
android:toYDelta="0%p"
android:duration="800"
android:repeatCount="0" />
<!-- android:fromYDelta="0%p" : 시작 위치 -->
<!-- android:toYDelta="30%p" : 종료 위치 -->
<!-- android:duration="2000" : 동작 시간 -->
<!-- android:repeatCount="-1" : 반복횟수(-1은 무한반복) -->
<!-- android:fillAfter="true" : 애니메이션 종료 후 위치 원상복귀 여부 -->
</set>