내 레이아웃에 3 Views
을 표시하고 싶지만 한 번에 2 개만 표시하고 싶습니다. 버튼을 누르면 가장 왼쪽 뷰가 왼쪽으로 미끄러 져 나오고 가운데 하나는 왼쪽 뷰의 시작 공간을 차지하고 가장 오른쪽 뷰는 스크린으로 미끄러 져 들어가야합니다. 다른보기 후에 새 위치 애니메이션보기 setVisibility (GONE)
이 내입니다 :
애니메이션하기 전에 :
애니메이션 후 : 애니메이션 (페인트 편집 ^^) 동안
여기
는 스크린 샷입니다 레이아웃 파일 :<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="3" >
<FrameLayout
android:id="@+id/stations_stations"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:layout_weight="1"
android:background="@drawable/fragment_border" />
<FrameLayout
android:id="@+id/stations_singlestation"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:layout_weight="2"
android:background="@drawable/fragment_border" />
<FrameLayout
android:id="@+id/stations_trip"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:layout_weight="1"
android:background="@drawable/fragment_border"
android:visibility="gone" />
</LinearLayout>
(10)는 그래서 아래의 코드를 사용하여 화면 밖으로 lefmost보기를 애니메이션 할 수 있어요 :
final View stationsContainer = findViewById(R.id.stations_stations);
Animation an = AnimationUtils.loadAnimation(this, R.anim.slide_out_left);
stationsContainer.startAnimation(an);
an.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
stationsContainer.setVisibility(View.GONE);
}
});
이 왼쪽으로 창 밖으로 가장 왼쪽 뷰를 애니메이션과 사라로 설정합니다. 중간 뷰를 새 위치에 애니메이션으로 만들 수도 있지만 애니메이션이 완료되면 중간 뷰는 원래 위치로 매우 짧은 시간 동안 점프 한 다음 올바른 위치로 이동합니다. 이 점프를 어떻게 피할 수 있습니까?
은 당신이있는 LinearLayout을 사용하고 View.GONE에 첫 번째의 가시성을 설정 버튼을 눌러에 수 있다고 생각. 그런 다음 다시 원하면 View.VISIBLE로 되돌립니다. Dunno, 애니메이션으로 어떻게 작동할까요? –
그건 내가 지금 가지고있는 것이지만,보기에는 좋지 않습니다. – nhaarman
[TranslateAnimation] (http://developer.android.com/reference/android/view/animation/TranslateAnimation.html)로 놀아보십시오. –