2011-10-18 10 views
0

gifアニメーションイメージを表示するカスタムビューがあります。私のlinearlayoutにカスタムビューを入れたときに生まれた問題、私のカスタムビューの下の他の要素は表示されません。これが私の見解です:カスタムビューで上記の要素がxmlに表示されない

public class GIFView extends View{   
private Movie movie; 
private InputStream is; 
private long moviestart; 
private long duration; 

public GIFView(Context context) { 
    super(context); 
    is=getResources().openRawResource(R.drawable.anim_cerca); 
    movie=Movie.decodeStream(is); 
    duration = movie.duration(); 
} 

public GIFView(Context context,AttributeSet set){ 
    super(context,set); 
    is=getResources().openRawResource(R.drawable.anim_cerca); 
    movie=Movie.decodeStream(is); 
    duration = movie.duration(); 
} 

public GIFView(Context context,AttributeSet set,int def){ 
    super(context,set,def); 
    is=getResources().openRawResource(R.drawable.anim_cerca); 
    movie=Movie.decodeStream(is); 
    duration = movie.duration(); 
} 

@Override 
protected void onDraw(Canvas canvas) { 
    super.onDraw(canvas); 
    long now=android.os.SystemClock.uptimeMillis(); 
    Paint p = new Paint(); 
    p.setAntiAlias(true); 
    if (moviestart == 0) 
     moviestart = now; 

    int relTime = (int)((now - moviestart) % duration); 

    movie.setTime(relTime); 
    movie.draw(canvas,0,0); 


    this.invalidate(); 
    }       
}  

と、これは私のレイアウトxmlです:私はこのようにID layoutGIFにレイアウトするためにカスタムビューを追加する活動の

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="match_parent" 
android:layout_height="match_parent" android:background="@drawable/sfondo"> 
<LinearLayout android:id="@+id/linearLayout2" 
    android:layout_height="wrap_content" android:layout_width="match_parent" 
    android:orientation="vertical"> 
    <LinearLayout android:id="@+id/linearLayout1" 
     android:layout_height="fill_parent" android:weightSum="1" 
     android:layout_width="fill_parent" android:orientation="horizontal"> 
     <ImageView android:layout_height="73dp" android:id="@+id/imageView1" 
      android:layout_weight="0.25" android:src="@drawable/trovachiavi" 
      android:layout_width="256dip"></ImageView> 
     <ImageButton android:id="@+id/infoButton" 
      android:background="@null" android:layout_height="47dp" 
      android:layout_marginLeft="10dip" android:layout_weight="0.25" 
      android:layout_marginTop="15dip" android:src="@drawable/info_mini" 
      android:layout_width="47dp"></ImageButton> 
    </LinearLayout> 
</LinearLayout> 
<LinearLayout android:id="@+id/layoutGIF" 
    android:layout_height="wrap_content" android:layout_width="wrap_content" 
    android:orientation="vertical" 
    android:layout_gravity="center"> 
</LinearLayout> 
<ImageButton android:id="@+id/avvia_cerca" 
    android:layout_height="wrap_content" android:layout_width="wrap_content" 
    android:layout_marginTop="10dp" android:layout_gravity="center|bottom" 
    android:background="@null"></ImageButton> 
</LinearLayout> 

LinearLayout lg = (LinearLayout)findViewById(R.id.layoutGIF); 
lg.setGravity(Gravity.CENTER); 
gif = new GIFView(this); 
lg.addView(gif, new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT)); 

私に何ができる?私はこれの下に要素が必要です!

+0

パッケージ名を使用してxmlにビューを追加し、その表示方法を確認できます。お役に立てれば。 –

+0

ここからわかるようにhttp://stackoverflow.com/questions/7795051/how-to-use-custom-views-in-layout-xml/7795114#comment9507382_7795114私はxmlに直接追加するのが悪い問題があります – JackTurky

答えて

0

アニメーションを使用している最善の方法は、gifは解決策ではないと思うすべてのアンドロイドデバイスからサポートされていません!

関連する問題