View를 좌우로 밀었을 때의 애니메이션 효과를 미리 만들어줍니다.
actViewFlipper.class
actViewFlipper.class
package View.Flipper;
import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.AnimationUtils;
import android.widget.ViewFlipper;
public class actViewFlipper extends Activity {
private ViewFlipper m_viewFlipper;
private int m_nPreTouchPosX = 0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
m_viewFlipper = (ViewFlipper)findViewById(R.id.viewFlipper);
m_viewFlipper.setOnTouchListener(MyTouchListener);
}
private void MoveNextView()
{
m_viewFlipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.appear_from_right));
m_viewFlipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.disappear_to_left));
m_viewFlipper.showNext();
}
private void MovewPreviousView()
{
m_viewFlipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.appear_from_left));
m_viewFlipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.disappear_to_right));
m_viewFlipper.showPrevious();
}
View.OnTouchListener MyTouchListener = new View.OnTouchListener()
{
public boolean onTouch(View v, MotionEvent event)
{
if (event.getAction() == MotionEvent.ACTION_DOWN)
{
m_nPreTouchPosX = (int)event.getX();
}
if (event.getAction() == MotionEvent.ACTION_UP)
{
int nTouchPosX = (int)event.getX();
if (nTouchPosX < m_nPreTouchPosX)
{
MoveNextView();
}
else if (nTouchPosX > m_nPreTouchPosX)
{
MovewPreviousView();
}
m_nPreTouchPosX = nTouchPosX;
}
return true;
}
};
}
main.xml
appear_from_right.xml
disappear_to_left.xml
disappear_to_right.xml
<?xml version="1.0" encoding="utf-8"?>
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"/>
<ViewFlipper
android198="@+id/viewFlipper"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android198="@+id/view1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:text="View 1"
android:textSize="30px"/>
<Button
android198="@+id/view2"
android:src="@drawable/icon"
android:text="View 2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ImageView
android198="@+id/view3"
android:src="@drawable/icon"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"/>
</ViewFlipper>
</LinearLayout>
appear_from_left.xml
</set>appear_from_left.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="-100%p"
android:toXDelta="0%p"
android:duration="500"/>
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="500" />
appear_from_right.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="100%p"
android:toXDelta="0%p"
android:duration="500"/>
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="500" />
</set>
disappear_to_left.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0%p"
android:toXDelta="-100%p"
android:duration="500"/>
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:duration="500" />
</set>disappear_to_right.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0%p"
android:toXDelta="100%p"
android:duration="500"/>
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:duration="500" />
</set>
'개발도구 > aOS - 안드로이드 개발' 카테고리의 다른 글
[안드로이드] webview 에 스크롤 삐져 나오는거 처리 (0) | 2011.09.16 |
---|---|
[안드로이드] webview 와 주소창 없애기 (0) | 2011.09.16 |
[안드로이드] split 특정값 찾아 배열만들기 (0) | 2011.09.09 |
[안드로이드] 진동오게 하기 vibrate (0) | 2011.09.08 |
[정리] 안드로이드 개발팁 총정리 사이트 (0) | 2011.09.08 |