Android Graphic and Animation 2

* สร้าง Project วาดภาพวิวบนโทรศัพท์ ประกอบด้วย พื้นสีฟ้า มีเมฆลอย 2 อัน มีพระจันทร์ มีพวงมาลัยหมุนอยู่ด้านล่าง
* ต้อง download ภาพที่เป็น png ชื่อต้องเป็นตัวเล็กเท่านั้น มาใส่ไว้ใน folder Drawable ที่สร้างเตรียมไว้เก็บรูปภาพ
* เวลา run ต้องไป run ที่ MainActivity ทุกครั้ง

Picture 2014-03-01 11_33_37 Picture 2014-03-01 11_43_02 Picture 2014-03-01 11_43_16

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:dither="true"
android:shape="oval"
>
<gradient
android:endColor="#ffff6600"
android:gradientRadius="150"
android:startColor="#ffffcc00"
android:type="radial"
android:useLevel="false"
/>
<size
android:height="100dp"
android:width="100dp"
/>
</shape>

Picture 2014-03-01 11_43_31 Picture 2014-03-01 11_43_44 Picture 2014-03-01 11_44_05

Mylayout3.XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#66ccff">
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="114dp"
android:layout_marginTop="28dp"
android:src="@drawable/sun" />

<ImageView
android:id="@+id/imageView2"
android:layout_width="180dp"
android:layout_height="100dp"
android:layout_alignParentLeft="true"
android:layout_toRightOf="@+id/imageView1"
android:src="@drawable/cloud_w_end" />

<ImageView
android:id="@+id/imageView3"
android:layout_width="120dp"
android:layout_height="100dp"
android:layout_alignParentRight="true"
android:layout_alignRight="@+id/imageView1"
android:src="@drawable/cloud_w_end" />

<ImageView
android:id="@+id/imageView4"
android:layout_width="fill_parent"
android:layout_height="150dp"
android:layout_alignParentBottom="true"
android:src="@drawable/ground" />

<ImageView
android:id="@+id/imageView5"
android:layout_width="fill_parent"
android:layout_height="150dp"
android:layout_alignParentBottom="true"

android:src="@drawable/ground" />

<ImageView
android:id="@+id/imageView6"
android:layout_width="250dp"
android:layout_height="100dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:src="@drawable/grear" />

</RelativeLayout>
-------------------------
Sun.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:dither="true"
android:shape="oval"
>
<gradient
android:endColor="#ffff6600"
android:gradientRadius="150"
android:startColor="#ffffcc00"
android:type="radial"
android:useLevel="false"
/>
<size
android:height="100dp"
android:width="100dp"
/>
</shape>

---------------------------------------------------
Sunset.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
android:ordering="sequentially"
>
<objectAnimator
android:duration="2000"
android:propertyName="x"
android:repeatMode="reverse"
android:repeatCount="infinite"
android:valueTo="1000"
android:valueType="floatType"
/>
</set>
-------------------------------------------------------------

Cloud.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
android:ordering="together"
>
<objectAnimator
android:duration="3000"
android:propertyName="x"
android:repeatMode="reverse"
android:repeatCount="infinite"
android:valueTo="400"
android:valueType="floatType"
/>
</set>
---------------------------------------------------------

Cloud2.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
android:ordering="together"
>
<objectAnimator
android:duration="3000"
android:propertyName="x"
android:repeatMode="reverse"
android:repeatCount="infinite"
android:valueTo="-200"
android:valueType="floatType"
/>
</set>

Picture 2014-03-01 11_49_53

MainActiviy.java

package petcharaporn.p.myapp1;

import android.os.Bundle;
import android.animation.AnimatorInflater;
import android.animation.AnimatorSet;
import android.app.Activity;
import android.view.Menu;
import android.widget.ImageView;

public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mylayout3);
ImageView sun=(ImageView)findViewById(R.id.imageView1);
AnimatorSet sn =(AnimatorSet)AnimatorInflater.loadAnimator(this,R.animator.sunset);
sn.setTarget(sun);
sn.start();

ImageView cloud=(ImageView)findViewById(R.id.imageView3);
AnimatorSet cl =(AnimatorSet)AnimatorInflater.loadAnimator(this,R.animator.cloud);
cl.setTarget(cloud);
cl.start();

ImageView cloud2=(ImageView)findViewById(R.id.imageView2);
AnimatorSet cl2 =(AnimatorSet)AnimatorInflater.loadAnimator(this,R.animator.cloud2);
cl2.setTarget(cloud2);
cl2.start();

ImageView gear=(ImageView)findViewById(R.id.imageView6);
AnimatorSet gr =(AnimatorSet)AnimatorInflater.loadAnimator(this,R.animator.gear);
gr.setTarget(gear);
gr.start();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}

หลังจาก run.. เมฆลอย พวงมาลัยหมุน พระอาทิตย์เคลื่อนที่

Picture 2014-03-01 11_52_58