2017-03-23 3 views
-1

버튼에서 clicklistener가 추가되었을 때 화면의 고정 된 위치로 버튼을 움직이려고했으나 relativelayout에 첨부되어있는 동안 작동하지 않습니다. 그래서 relativelayout을 포함한 버튼이 움직이게됩니다. 문제는 중첩 된 뷰 그룹 내에 레이아웃을 첨부 할 때 해결책이라고 생각합니다. 미리 감사드립니다.부모 (RelativeLayout) 레이아웃에 연결된 경우 애니메이션이 작동하지 않습니까?

b = (Button) findViewById(R.id.simpleButton); 
    relativeLayout = (RelativeLayout) findViewById(R.id.wrapper); 
    b.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      b.startAnimation(animations()); 
     } 
    }); 
    relativeLayout.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      relativeLayout.setAnimation(animations()); 
     } 
    }); 
} 


private TranslateAnimation animations() { 
    TranslateAnimation translateAnimation = new TranslateAnimation(0f, 0f, 0, -40); 
    translateAnimation.setDuration(1000); 
    translateAnimation.setInterpolator(new AccelerateInterpolator()); 
    return translateAnimation; 
} 

다음은 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"> 
    <RelativeLayout 
android:id="@+id/wrapper" 
android:layout_width="match_parent" 
android:background="#cbcbbc" 
android:layout_height="60dp"> 
    <Button 
     android:id="@+id/simpleButton" 
     android:layout_width="wrap_content" 
     android:layout_height="40dp" 
     android:text="Go next page" /> 
    </RelativeLayout> 

    </LinearLayout> 
+0

포스트'xml' 레이아웃을. – azizbekian

+0

달성하고자하는 목표는 무엇입니까? – azizbekian

+0

버튼을 누를 때 레이아웃은 상단에서부터 나오고 그 위치에 도달합니다. 비슷하게 상위 레이아웃을 포함하여 전체 레이아웃에서 레이아웃을 얻고 싶습니다. 버튼 클릭만으로 동작하며, 클릭은 –

답변

2

RelativeLayout이 추가 :

android:clickable="true" 

대신 :

relativeLayout.setAnimation(animations()); 

이를 수행

relativeLayout.startAnimation(animations()); 
+0

가 작동하지 않습니다. –

+0

고맙습니다. @azizbekian –

관련 문제