class MainActivity
package org.androidtown.myanim;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
TextView textView;
ViewGroup viewGroup;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView=(TextView)findViewById(R.id.textView1);
viewGroup=(ViewGroup)findViewById(R.id.activity_main);
}
public void onButton1Click(View v){
//텍스트 애니메이션
Animation animation = AnimationUtils.loadAnimation(this, R.anim.translate);
textView.startAnimation(animation);
//화면 전체 움직이기
// viewGroup.startAnimation(animation);
}
}
R.layout.activity_main
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="org.androidtown.myanim.MainActivity"
android:background="@android:color/holo_green_light">
<TextView
android:text="안녕하세요"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/textView1"
android:textColor="@color/colorAccent"
android:textSize="30sp" />
<Button
android:text="에니메이션"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:id="@+id/button"
android:onClick="onButton1Click"
/>
</RelativeLayout>
translate.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="1500"
/>
</set>
여기서 p 를 넣어야 된다. p를 넣어야 화면 크기나 방향 변하면 화면의 100% 가 되는 지점 또는 0% 가 되는 지점에서 시작된다.
댓글 ( 4)
댓글 남기기