2012-05-16 3 views
3

잠시 동안 인터넷을 샅샅이 뒤지고 있으며 애니메이션 문제를 해결할 수있는 솔루션을 찾지 못했습니다.Android보기 애니메이션

목록보기에서 항목 중 하나를 클릭하면 더 많은 정보가 하단에서 애니메이션으로 표시되어 몇 줄의 추가 정보를 얻을 수 있습니다. 내가 제대로 작동하려면 애니메이션을 얻을 수 있도록

<?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" > 




<LinearLayout 
    android:id="@+id/friendActivityList" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/friendInfo" 
    android:background="@color/grey" 
    android:orientation="vertical" 
    android:visibility="gone" > 

    <RelativeLayout 
     android:id="@+id/RelativeLayout04" 
     android:layout_width="match_parent" 
     android:layout_height="@dimen/freind_activity_list_height" > 

     <ImageView 
      android:id="@+id/ImageView04" 
      android:layout_width="wrap_content" 
      android:layout_height="25dp" 
      android:layout_margin="5dp" 
      android:src="@drawable/logo_d" /> 

     <TextView 
      android:id="@+id/TextView04" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerVertical="true" 
      android:layout_toRightOf="@+id/ImageView04" 
      android:text="TextView" 
      android:textColor="@color/black" 
      android:textSize="17dp" /> 
    </RelativeLayout> 

    <RelativeLayout 
     android:id="@+id/RelativeLayout03" 
     android:layout_width="match_parent" 
     android:layout_height="@dimen/freind_activity_list_height" > 

     <ImageView 
      android:id="@+id/ImageView03" 
      android:layout_width="wrap_content" 
      android:layout_height="25dp" 
      android:layout_margin="5dp" 
      android:src="@drawable/logo_d" /> 

     <TextView 
      android:id="@+id/TextView03" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerVertical="true" 
      android:layout_toRightOf="@+id/ImageView03" 
      android:text="TextView" 
      android:textColor="@color/black" 
      android:textSize="17dp" /> 
    </RelativeLayout> 

    <RelativeLayout 
     android:id="@+id/RelativeLayout02" 
     android:layout_width="match_parent" 
     android:layout_height="@dimen/freind_activity_list_height" > 

     <ImageView 
      android:id="@+id/ImageView02" 
      android:layout_width="wrap_content" 
      android:layout_height="25dp" 
      android:layout_margin="5dp" 
      android:src="@drawable/logo_d" /> 

     <TextView 
      android:id="@+id/TextView02" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerVertical="true" 
      android:layout_toRightOf="@+id/ImageView02" 
      android:text="TextView" 
      android:textColor="@color/black" 
      android:textSize="17dp" /> 
    </RelativeLayout> 

    <RelativeLayout 
     android:id="@+id/relativeLayout1" 
     android:layout_width="match_parent" 
     android:layout_height="@dimen/freind_activity_list_height" > 

     <ImageView 
      android:id="@+id/imageView1" 
      android:layout_width="wrap_content" 
      android:layout_height="25dp" 
      android:layout_margin="5dp" 
      android:src="@drawable/logo_d" /> 

     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerVertical="true" 
      android:layout_toRightOf="@id/imageView1" 
      android:text="TextView" 
      android:textColor="@color/black" 
      android:textSize="17dp" /> 
    </RelativeLayout> 

    <RelativeLayout 
     android:id="@+id/RelativeLayout01" 
     android:layout_width="match_parent" 
     android:layout_height="@dimen/freind_activity_list_height"> 

     <ImageView 
      android:id="@+id/ImageView01" 
      android:layout_width="wrap_content" 
      android:layout_height="25dp" 
      android:layout_margin="5dp" 
      android:src="@drawable/logo_d" /> 

     <TextView 
      android:id="@+id/TextView01" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerVertical="true" 
      android:layout_toRightOf="@+id/ImageView01" 
      android:text="TextView" 
      android:textColor="@color/black" 
      android:textSize="17dp" /> 
      </RelativeLayout> 
     </LinearLayout> 






     <RelativeLayout 
      android:id="@+id/friendInfo" 
      android:layout_width="wrap_content" 
      android:layout_height="60dp" 
      android:background="@drawable/bg_list_item_n" > 

    <ImageView android:id="@+id/imgCompany" 
     android:layout_marginLeft="5dp" 
     android:layout_centerVertical="true" 
     android:layout_width="60dp" 
     android:src="@drawable/ic_launcher" 
     android:scaleType="centerInside" 
     android:layout_alignParentLeft="true" 
     android:layout_height="50dp"> 
    </ImageView> 



    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="60dp" 
     android:layout_toRightOf="@id/imgCompany" 
     android:background="@android:color/transparent" 
     android:gravity="left|center" 
     android:orientation="vertical" 
     android:paddingLeft="5dp" > 

      <TextView android:id="@+id/lblCompanyName" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textColor="@color/white" 
       android:textStyle="bold" 
       android:textSize="13dp" 
       android:text="Company Name"> 
      </TextView> 

      <TextView android:id="@+id/lblReawrdDesc" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textColor="@color/white" 
       android:textSize="13dp" 
       android:text="Reawrd Description"> 
      </TextView> 

      <TextView android:id="@+id/lblScores" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textColor="@color/white" 
       android:textSize="13dp" 
       android:singleLine="true" 
       android:text="My Score: 13434 | Top Score: 344425"> 
      </TextView> 

     </LinearLayout> 

    </RelativeLayout> 

    </RelativeLayout> 

이의 대부분은 홀더 정보를 배치한다 : 즉 단순히 내가 여기,이 목록의 항목을 사용하여 XML 파일 메신저 내부에 가지고있는 LinearLayout이다. 내가 목록보기 항목에 전체 공간을 클릭했을 때 가정 - 투 - 애니메이션보기는에 소요

listviewFriends.setOnItemClickListener(new OnItemClickListener() {//this is the listView that im animating inside of 

     public void onItemClick(AdapterView<?> parent, View view,final int pos, long id) { 
      Log.v("ListItemClicked", "this position was clicked: "+pos); 
      if(friendInfoList != null){ 
       friendInfoList.clearAnimation();//this is the new view that gets animated and is supposed to push everything below it out of the way 
       friendInfoList.setVisibility(View.GONE); 
      } 
      friendInfoList = (LinearLayout) view.findViewById(R.id.friendActivityList); 
      friendInfoList.setVisibility(View.VISIBLE); 
      friendInfoList.startAnimation(infoAnim); 

     } 
    }); 

    infoAnim = new TranslateAnimation(0,0, -150, 0);//this is the animation im using 
    infoAnim.setDuration(1000); 
    infoAnim.setFillAfter(true); 

이 없음 결과가되는 것을 다음은 애니메이션에 사용하는 메신저 코드입니다 끝은 흰색이고보기는 위에서 아래로 움직입니다. 위치는 정확하지만 그 아래에있는 모든 것을 움직이게하고 밀어 내고 싶습니다. 대신 즉시 모든 것을 푸시하고 그 공간을 채우기 위해 움직입니다.

어떻게하면 애니메이션 대신 즉시 모든 것을 푸는 지 알 수 있습니다. 이 효과를 얻을 수 있습니까? 어떤 도움이라도 대단히 감사하겠습니다.

또한 나는 다른 뷰의 ontop을 애니메이션으로 만들 수있는 방법을 알고 있지만 실제로 모든 것을 푸시해야합니다.

답변

4

이 트릭은 사용자 고유의 애니메이션 하위 클래스를 만드는 것입니다.

public void togglePreview() 
{ 
    if(_expanded) _preview.startAnimation(_animation.collapse()); 
    else _preview.startAnimation(_animation.expand()); 

    _expanded = !_expanded; 
    getParent().requestLayout(); 
} 
+0

감사합니다 :

public class ExpandAnimation extends Animation { private int _targetHeight; private View _view; private boolean _down; public ExpandAnimation(View view, int targetHeight) { _view = view; _targetHeight = targetHeight; } @Override protected void applyTransformation(float interpolatedTime, Transformation t) { int newHeight; if(_down) { newHeight = (int) (_targetHeight * interpolatedTime); } else { newHeight = (int) (_targetHeight * (1 - interpolatedTime)); } _view.getLayoutParams().height = newHeight; _view.requestLayout(); } public ExpandAnimation expand() { _down = true; return this; } public ExpandAnimation collapse() { _down = false; return this; } @Override public void initialize(int width, int height, int parentWidth, int parentHeight) { super.initialize(width, height, parentWidth, parentHeight); } @Override public boolean willChangeBounds() { return true; } } 

그럼 당신은 확대 될 전망이보기에 그 적용 할 수 있습니다! 이것은 분명히 내 질문에 대답했다. Im did not는 왜 나 자신을 애니메이션으로 서브 클래 싱하는 것을 생각하지 않았는가?하지만 지금은 모두 도움이된다. – Intrivix

관련 문제