뷰가 애니메이션 된 후 setVisibility가 작동하지 않는 이유는 무엇입니까?
textView가 보이지 않는 이유는 무엇입니까?
내 레이아웃 xml은 다음과 같습니다.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/tvRotate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rotate Me"
/>
</LinearLayout>
.. 내 활동은 다음과 같습니다.
public class RotateMeActivity extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tvRotate = (TextView) findViewById(R.id.tvRotate);
RotateAnimation r = new RotateAnimation(0, 180, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
r.setDuration(0);
r.setFillAfter(true);
tvRotate.startAnimation(r);
tvRotate.setVisibility(View.INVISIBLE);
}
}
내 목표는 뷰를 회전 한 다음 setVisibility를 설정하여 코드에서 숨기고 표시 할 수 있도록하는 것입니다. 다음은 작동하지만 setRotation은 API 레벨 11에서만 사용할 수 있습니다. API 레벨 10에서 수행 할 방법이 필요합니다.
tvRotate.setRotation(180);//instead of the RotateAnimation, only works in API Level 11
tvRotate.setVisibility(View.INVISIBLE);
나를 clearAnimation
위해 View를 호출 하면 문제가 해결되었습니다. 제 경우에는 fillAfter를 true로 설정 한 후 변환을 수행 한 후 View를 원래 위치로 되돌리고 싶었습니다.
모든 애니메이션 (Android 3.0 이전)은 원래 뷰가 아닌 뷰의 스냅 샷 인 비트 맵에 실제로 적용됩니다. 이후 채우기를 참으로 설정하면 실제로 비트 맵이 뷰 대신 화면에 계속 표시된다는 것을 의미합니다. 이것이 사용시 가시성이 변경되지 않는 setVisibility
이유와 뷰가 새로운 (회전 된) 경계에서 터치 이벤트를 수신하지 않는 이유이기도합니다. (하지만 180도 회전하므로 문제가되지 않습니다).
이 문제를 해결하는 또 다른 방법은 애니메이션 뷰를 다른 뷰로 래핑하고 해당 래퍼 뷰의 가시성을 설정하는 것입니다.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:id="@+id/animationHoldingFrame"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tvRotate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rotate Me"
/>
</FrameLayout>
</LinearLayout>
그리고 코드는 다음과 같이됩니다.
TextView tvRotate = (TextView) findViewById(R.id.tvRotate);
FrameLayout animationContainer = (FrameLayout)findViewById(R.id.animationHoldingFrame)
RotateAnimation r = new RotateAnimation(0, 180, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
r.setDuration(0);
r.setFillAfter(true);
tvRotate.startAnimation(r);
animationContainer.setVisibility(View.INVISIBLE);
애니메이션이 완료된 후 setVisibility 전에 이것을 사용하십시오.
anim.reverse();
anim.removeAllListeners();
anim.end();
anim.cancel();
anim은 ObjectAnimator입니다.
그러나 Animation 클래스를 사용하는 경우 다음을 수행하십시오.
view.clearAnimation();
on the view upon which the animation was performed
I ended up requiring API Level 11 and using setRotation to accomplish this. This seems like a pretty simple requirement that can't be done pre-Honeycomb though. All i wanted to do was rotate a button and then hide/show it.
I came up with a workaround for this: basically right before you call setVisibility(View.GONE), do an animation with duration=0 setFillAfter(false) and have the angle from/to set to the current angle of rotation.
This will clear the setFillAfter bitmap and allow the view to be gone.
참고URL : https://stackoverflow.com/questions/8690029/why-doesnt-setvisibility-work-after-a-view-is-animated
'Program Tip' 카테고리의 다른 글
Eclipse에 오류가 표시되지만 찾을 수 없습니다. (0) | 2020.11.22 |
---|---|
데이터베이스에 대한 CREATE 스크립트 내보내기 (0) | 2020.11.22 |
C #에서 SHA1 알고리즘을 사용한 해싱 (0) | 2020.11.22 |
Android Studio-XML 편집기 자동 완성이 지원 라이브러리에서 작동하지 않음 (0) | 2020.11.22 |
MongoDB는 한 번에 여러 컬렉션 쿼리 (0) | 2020.11.21 |