i have develop one application in which i want to play gif animation.
for that i have refer this
CODE
public class GIFDemo extends GraphicsActivity {
ImageView imageView1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
imageView1 = (ImageView) findViewById(R.id.imageView1);
}
private static class GIFView extends View{
Movie movie,movie1;
InputStream is=null,is1=null;
long moviestart;
long moviestart1;
public GIFView(Context context) {
super(context);
is=context.getResources().openRawResource(R.drawable.border_gif);
movie=Movie.decodeStream(is);
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawColor(0xFFCCCCCC);
super.onDraw(canvas);
long now=android.os.SystemClock.uptimeMillis();
if (moviestart == 0) { // first time
moviestart = now;
}
if(moviestart1==0)
{
moviestart1=now;
}
int relTime = (int)((now - moviestart) % movie.duration()) ;
// int relTime1=(int)((now - moviestart1)% movie1.duration());
movie.setTime(relTime);
// movie1.setTime(relTime1);
movie.draw(canvas,10,10);
//movie1.draw(canvas,10,100);
this.invalidate();
}
}
}
Main :
<?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"
/>
<ImageView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/imageView1"
android:src="@drawable/icon"></ImageView>
</LinearLayout>
so problem is i want to set class GIFView in Imageview so i have refer post like this
but not get proper example. so can you give me proper example and explanation that how can i set view in ImageView
Thanks
nik
I don’t think it is meaningful to ‘set the view’ of an
ImageView(in the way you are suggesting), and I don’t think you even need anImageViewin this case. You have implemented a customViewthat is able to draw a GIF without any dependency on theImageViewclass – you just have to use it!With minimal changes, assuming the
GIFViewworks, you can just instantiate aGIFViewand then add it to the main layout. Let youronCreatebe as follows:You can get rid of the ImageView from the layout entirely and just use your
GIFViewthat was instantiated in code. Alternatively, you can make yourGIFViewa standalone (non-inner) class and add it to your XML layout by specifying the full package name, e.g.You would also need to write the view constructor
GIFView(Context context, AttributeSet attrs)because that is the one that is expected when using XML.