528
No
class MainActivity
package kr.co.braverokmc.mygraphanimation;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ProgressBar;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
Animation grow;
ProgressBar progressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progressBar=(ProgressBar)findViewById(R.id.progress1);
grow= AnimationUtils.loadAnimation(getApplicationContext(), R.anim.grow);
progressBar.setAnimation(grow);
}
//모든 액티비티가 초기화 과정후 시작되는 메소드
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
Toast.makeText(getApplicationContext() ,
"onWindowFocusChanged 호출됨 : " + hasFocus ,Toast.LENGTH_SHORT).show();
if(hasFocus){
grow.start();
}else{
grow.reset();
}
}
}
R.layout.activity_main
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/line1">
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:text="사과"
android:textSize="30dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
/>
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progress1"
android:layout_weight="1"
android:layout_gravity="center_horizontal|center_vertical"
/>
</LinearLayout>
</LinearLayout>
grow.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:fromXScale="0.0"
android:fromYScale="1.0"
android:toXScale="1.0"
android:toYScale="1.0"
android:pivotX="0%p"
android:pivotY="50%p"
android:duration="10000"
/>
</set>
댓글 ( 4)
댓글 남기기