フラグメントにフレームごとのアニメーションがあり、
アニメーションを別の場所に配置する必要がありますが、
これまでのところ、1 つのアニメーション [頭にあるもの]を作成できます。
では、他のアニメーションを特定の X & Y 位置に配置してアニメーション化するにはどうすればよいですか?
ここで使用しているコード:
.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#FF0000">
<RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content">
<ImageView
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:src="@drawable/home_bgnd" android:scaleType="fitXY" />
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:id="@+id/imgTesto"
android:contentDescription="@string/imageFrag1"
android:layout_x="265dp"
android:layout_y="23dp"
android:layout_width="41dp"
android:layout_height="41dp"
android:src="@drawable/c_0"
/>
<ImageView android:id="@+id/imgTesto1"
android:contentDescription="@string/imageFrag1"
android:layout_x="265dp"
android:layout_y="100dp"
android:layout_width="41dp"
android:layout_height="41dp"
android:src="@drawable/c_0"
/>
</AbsoluteLayout>
</RelativeLayout>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TesteoB" />
</LinearLayout>
そして.java
public class HomeTab extends Fragment {
/* (non-Javadoc)
* @see android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
*/
AnimationDrawable animation;
AnimationDrawable animation1;
//ImageButton yourButton = new ImageButton(this);
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
if (container == null) {
// We have different layouts, and in one of them this
// fragment's containing frame doesn't exist. The fragment
// may still be created from its saved state, but there is
// no reason to try to create its view hierarchy because it
// won't be displayed. Note this is not needed -- we could
// just run the code below, where we would create and return
// the view hierarchy; it would just never be used.
return null;
}
//animation 0
animation = new AnimationDrawable();
animation.addFrame(getResources().getDrawable(R.drawable.c_0), 100);
animation.addFrame(getResources().getDrawable(R.drawable.c1), 100);
animation.addFrame(getResources().getDrawable(R.drawable.c2), 100);
animation.addFrame(getResources().getDrawable(R.drawable.c3), 100);
animation.addFrame(getResources().getDrawable(R.drawable.c4), 100);
animation.addFrame(getResources().getDrawable(R.drawable.c5), 100);
animation.addFrame(getResources().getDrawable(R.drawable.c6), 100);
animation.addFrame(getResources().getDrawable(R.drawable.c7), 100);
animation.addFrame(getResources().getDrawable(R.drawable.c8), 100);
animation.addFrame(getResources().getDrawable(R.drawable.c9), 100);
animation.addFrame(getResources().getDrawable(R.drawable.c10), 100);
animation.addFrame(getResources().getDrawable(R.drawable.c9), 100);
animation.addFrame(getResources().getDrawable(R.drawable.c8), 100);
animation.addFrame(getResources().getDrawable(R.drawable.c7), 100);
animation.addFrame(getResources().getDrawable(R.drawable.c6), 100);
animation.addFrame(getResources().getDrawable(R.drawable.c5), 100);
animation.addFrame(getResources().getDrawable(R.drawable.c4), 100);
animation.addFrame(getResources().getDrawable(R.drawable.c3), 100);
animation.addFrame(getResources().getDrawable(R.drawable.c2), 100);
animation.addFrame(getResources().getDrawable(R.drawable.c1), 100);
animation.setOneShot(false);
//animation 1
animation1 = new AnimationDrawable();
animation1.addFrame(getResources().getDrawable(R.drawable.c_0), 100);
animation1.addFrame(getResources().getDrawable(R.drawable.c1), 100);
animation1.addFrame(getResources().getDrawable(R.drawable.c2), 100);
animation1.addFrame(getResources().getDrawable(R.drawable.c3), 100);
animation1.addFrame(getResources().getDrawable(R.drawable.c4), 100);
animation1.addFrame(getResources().getDrawable(R.drawable.c5), 100);
animation1.addFrame(getResources().getDrawable(R.drawable.c6), 100);
animation1.addFrame(getResources().getDrawable(R.drawable.c7), 100);
animation1.addFrame(getResources().getDrawable(R.drawable.c8), 100);
animation1.addFrame(getResources().getDrawable(R.drawable.c9), 100);
animation1.addFrame(getResources().getDrawable(R.drawable.c10), 100);
animation1.addFrame(getResources().getDrawable(R.drawable.c9), 100);
animation1.addFrame(getResources().getDrawable(R.drawable.c8), 100);
animation1.addFrame(getResources().getDrawable(R.drawable.c7), 100);
animation1.addFrame(getResources().getDrawable(R.drawable.c6), 100);
animation1.addFrame(getResources().getDrawable(R.drawable.c5), 100);
animation1.addFrame(getResources().getDrawable(R.drawable.c4), 100);
animation1.addFrame(getResources().getDrawable(R.drawable.c3), 100);
animation1.addFrame(getResources().getDrawable(R.drawable.c2), 100);
animation1.addFrame(getResources().getDrawable(R.drawable.c1), 100);
animation1.setOneShot(false);
View V = inflater.inflate(R.layout.tab_home_layout, container, false);
ImageView imageView = (ImageView)V.findViewById(R.id.imgTesto); //mestrua imagen ok, en el fragmentus
//animation 0
imageView.setBackgroundDrawable(animation);
imageView.post(new Starter());
//animation 1
/*
ImageView imageView1 = (ImageView)V.findViewById(R.id.imgTesto1); //mestrua imagen ok, en el fragmentus
imageView1.setBackgroundDrawable(animation);
imageView1.post(new Starter());
*/
return V;
}
class Starter implements Runnable {
public void run() {
animation.start();
}
}
}
animation0、animation1、animationNを作成しないようにするにはどうすればよいですか
場所が違うだけで同じですか?
また、廃止されたものを使用していることに注意してくださいAbsoluteLayout
ありがとう!