2011-04-21 2 views
1

프로젝트에서 런타임에 위젯을 화면 위로 이동할 수 있어야합니다 (역방향 폭포와 같은). 어떤 사람은 런타임 중에 화면의 한 위치에서 다른 위치 (절대 레이아웃 사용)로 단추를 이동하는 방법의 예를 보여줄 수 있습니까?Android 앱솔루트 레이아웃/매개 변수 (런타임 중 위젯 이동)

나는 그것이 아마 희망

AbsoluteLayout.LayoutParams 

또는 params.addRule 사용한다 알고있다. 화면의
_ __ _ __ _ __ _ __ _ __ _ __ _ __ (최고 :하지만 나에게

예를 들어

을 가르쳐주의 해주세요)
| [버튼]
| -
| -
| -
| -
| -
| -
| -
| >
| [버튼]
_ __ _ __ _ __ _ __ _ __ _ __ _ __ (화면 하부)

답변

2

http://developerlife.com/tutorials/?p=343

가입일 다음은 슬라이드에서 왼쪽으로의 애니메이션입니다 (보기의 너비를 가로 질러 오른쪽에서 왼쪽으로). "/res/anim/slide_right.xml" : 여기

<?xml version="1.0" encoding="utf-8"?> 

<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator"> 
    <translate android:fromXDelta="100%p" android:toXDelta="0" android:duration="150" /> 
</set> 

위의 하나 사용하는 다른 애니메이션 시퀀스입니다 (@의 ANIM/slide_right.xml -> "/res/anim/slide_right.xml") :

<?xml version="1.0" encoding="utf-8"?> 

<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android" 
     android:delay="10%" 
     android:order="reverse" 
     android:animation="@anim/slide_right" /> 

그래서 당신이 만들 수는 시퀀스를 XML로 저장하고 Android 프로젝트 리소스의 "/res/anim/some_file.xml"에 넣습니다. 이 XML 파일을 만드는 방법에 대한 자세한 내용은 여기를 참조하십시오.

또한 코드하여이 작업을 수행 할 수 있습니다 : 다음

AnimationSet set = new AnimationSet(true); 

    Animation animation = new AlphaAnimation(0.0f, 1.0f); 
    animation.setDuration(100); 
    set.addAnimation(animation); 

    animation = new TranslateAnimation(
     Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, 
     Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 0.0f 
); 
    animation.setDuration(500); 
    set.addAnimation(animation); 

    LayoutAnimationController controller = 
     new LayoutAnimationController(set, 0.25f); 
    button.setLayoutAnimation(controller); 

과 :

public static Animation runSlideAnimationOn(Activity ctx, View target) { 
    Animation animation = AnimationUtils.loadAnimation(ctx, 
                android.R.anim.slide_right); 
    target.startAnimation(animation); 
    return animation; 
} 
+0

당신을 감사합니다! 이게 많이 도움이 될거야. –