Please Enable JavaScript!
Gon[ Enable JavaScript ]

반응형

안드로이드(Android) ListActivity 로 구현한 목록에 애니메이션 적용하기

 

개발환경 : window 7 64bit, Eclipse Mars, Android 4.2.2

 

이전 아티클에서 ListActivity 클래스를 상속받아

목록페이지를 구현하였습니다. 이 목록 페이지가

뜰 때 애니메이션 효과를 얻을수 있도록

구현합니다.


 

리스트를 만드는 Activity 에서 애니메이션을 구현할려면

setLayoutAnimation() 함수의 인수로

LayoutAnimationController 객체를 넘기면 됩니다.

ListView 속성값 layoutAnimation xml 값을

셋팅하는 것과 같습니다.

android:layoutAnimation="@drawable/list_layout_controller"

 

LayoutAnimationController controller = AnimationUtils
            .loadLayoutAnimation(this, R.drawable.list_layout_controller);
getListView().setLayoutAnimation(controller);

 

loadLayoutAnimation() 인수로 들어가는 xml

다음과 같습니다.

 

list_layout_controller.xml

 

<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
 android:delay="80%"
 android:animation="@drawable/scale" />

 

scale.xml 에는 애니메이션효과를 위한 옵션값들이

들어가게 되는데 duration 은 작아졌다가 원래 크기로

돌아오는데 걸리는 시간입니다.

 

scale.xml

 

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/accelerate_interpolator" >

    <scale
        android:duration="500"
        android:fromXScale="0.3"
        android:fromYScale="0.3"
        android:pivotX="10%"
        android:pivotY="10%"
        android:startOffset="100"
        android:toXScale="1"
        android:toYScale="1.0" />

</set>

 

리스트를 표현한 activity 의 전체 소스입니다.


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class SampleActivity16 extends Activity {

	private TextView country;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_sample_activity16);

		country = (TextView) findViewById(R.id.myCountry);
		Button SelectCountryButton = (Button) findViewById(R.id.selectCountryButton);
		SelectCountryButton
				.setOnClickListener(countryButtonOnClickListener);
	}

	private Button.OnClickListener countryButtonOnClickListener = 
                                        new Button.OnClickListener() {
		public void onClick(View v) {
			Intent intent = new Intent();
			intent.setClass(SampleActivity16.this, AndListActivity.class);

			startActivityForResult(intent, 0);
		}
	};

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		if (requestCode == 0) {
			switch (resultCode) {
			case RESULT_OK:
				country.setText(data.getStringExtra("country"));
				break;
			case RESULT_CANCELED:
				break;

			}
		}
	}
}

 

 

반응형
Posted by 녹두장군1
,