2016-10-23 2 views
2

버튼 클릭, 아래에서 나타나는 단편에 애니메이션을 추가하려고합니다.Android : 조각을 위로 밀어내는 방법?

조각 레이아웃

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_alignParentBottom="true" 
    android:orientation="vertical" > 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="50dp" 
     android:background="@color/wallet_holo_blue_light" 
     android:layout_gravity="center" 
     android:text="This is a fragmentt layout" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" /> 

</RelativeLayout> 

슬라이드 여기를 호출

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" 
    android:duration="@android:integer/config_mediumAnimTime"> 

    <translate xmlns:android="http://schemas.android.com/apk/res/android" 
     android:duration="@android:integer/config_mediumAnimTime" 
     android:fromYDelta="50.0%p" 
     android:interpolator="@android:anim/decelerate_interpolator" 
     android:toYDelta="30" /> 
</set> 

up.xml :

public void onClick(View view) { 

      if(view == button){ 

     FragmentManager fragmentManager = getFragmentManager(); 
     FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); 
     FragmentOnMap hello = new FragmentOnMap(); 

     fragmentTransaction.add(R.id.fragment_container, hello, "HELLO"); 
     fragmentTransaction.setCustomAnimations(R.animator.slide_up,0); 
     fragmentTransaction.commit(); 
    } 


} 

Android Fragments and animation

위로 밀어하는 방법을 보여줍니다 아래, 난 그냥 단편 애니메이션 쪽으로. 따라서 setcustomanimation() 함수의 두 번째 인수에 대한 내 질문.

커밋 바로 전에 fragmentTransaction.setCustomAnimations()을 사용해 보았지만 도움이되지 않았습니다.

하단에 표시되지만 전환 효과는 없습니다. 모든 안내가 유용 할 것입니다. 감사합니다.

+2

가능한 중복 http://stackoverflow.com/questions/을 4817900/android-fragments-and-animation) – jakubbialkowski

답변

1

setCustomAnimationadd 전에는 그게 전부입니다.

또한 app 대신에 조각 (v4)의 지원 라이브러리를 사용해야하고 조각을 사용할 때 getSupportFragmentManager를 호출하고 코드의 모든 부분을 수정해야하므로 코드에 문제가 발생합니다. 지원 라이브러리를 사용하십시오.

이를 변경하지 않으려면, 당신은 slide_up 애니메이션이 코드를 수행 할 수 있습니다

<?xml version="1.0" encoding="utf-8"?> 
<objectAnimator 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:interpolator="@android:anim/accelerate_decelerate_interpolator" 
    android:propertyName="translationY" 
    android:valueType="floatType" 
    android:valueFrom="1280" 
    android:valueTo="0" 
    android:duration="@android:integer/config_mediumAnimTime"/> 
[안드로이드 단편 애니메이션] (의
+0

setcustomanimation의 두 번째 인수는 무엇입니까? setCustomAnimation (R.id.slideup ,?) – AIS

+0

fragmentTransaction.setCustomAnimations (R.animator.slide_up, 0); 지원 라이브러리를 사용하는 경우 R.anim.slide_up. –

+0

수정 된 코드를 참조하십시오. 움직이지 않았습니까? slide_up을 사용했습니다. 단편이 나타납니다. 슬라이딩 효과가 없습니다. – AIS

관련 문제