2012-01-27 7 views
0

私はそれの下にイメージビューを持つギャラリーを作成するチュートリアルに従ってきました。私がやりたいことは、ギャラリーを下に置き、イメージビューをその上に置くだけですが、XMLでそれらを切り替えると、ClassCastExceptionが表示されます。ここで ClassCastException(Gallery + ImageView)

はXMLです:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/LinearLayout01" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="@drawable/backrepeat" 
android:orientation="vertical" > 

<ImageView 
    android:id="@+id/ImageView01" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 

<Gallery 
    android:id="@+id/gallery" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" /> 

</LinearLayout> 
非作業バージョンである

が、ImageViewの作品以上のギャラリーを置きます。ログから

01-26 22:20:13.673: E/AndroidRuntime(349): Caused by: java.lang.ClassCastException:   android.widget.ImageView 
01-26 22:20:13.673: E/AndroidRuntime(349): at  com.appinfluence.fanapp.v1.Photos.onCreate(Photos.java:36) 

のonCreate:

Gallery gallery = (Gallery) findViewById(R.id.gallery); 
    gallery.setAdapter(new ImageAdapter(Photos.this)); 

    imgView = (ImageView)findViewById(R.id.ImageView01); 
    imgView.setImageResource(mImageIds[0]); 


    gallery.setOnItemClickListener(new OnItemClickListener() { 
     public void onItemClick(AdapterView parent, View v, int position, long id) { 
      imgView.setImageResource(mImageIds[position]); 
     } 
    }); 
} 

その他の役に立つコード:

public View getView(int position, View convertView, ViewGroup parent) { 
     ImageView imageView = new ImageView(mContext); 

     imageView.setImageResource(mImageIds[position]); 
     imageView.setLayoutParams(new Gallery.LayoutParams(150, 100)); 
     imageView.setScaleType(ImageView.ScaleType.FIT_XY); 
     imageView.setBackgroundResource(mGalleryItemBackground); 

     return imageView; 
    } 

http://4.bp.blogspot.com/_I2Ctfz7eew4/S_JxIfgKrfI/AAAAAAAAAzA/m1KUSIugojY/s1600/Gallery2.1.PNG

+0

うんImageViewのは、上記で、ギャラリーは以下であれば、私も同じ問題を取得しています。 –

+0

このコードを表示することもできますか:com.appinfluence.fanapp.v1.Photos.onCreate(Photos.java:36) –

+0

すでにあります。 –

答えて

0

ちょっとNickNelsonちょうど私はあなたの問題の解決策を得ました、ちょうどそれが動作するプロジェクトをきれいにする。

サンプルスクリーンショット

enter image description here

+0

なぜトップにギャップがありますか? –

+0

** 4/7 **とGoogle画像のギャップ?画像の高さのために。 –

+0

チェックが今すぐスクリーンショットに置き換えられました。 –

0

別のを使用する必要はありません0のレイアウトでは、ギャラリーが画像を表示します。 ImageViewを削除し、それを確認...

編集

だけでプロジェクトを清掃してください。 (yugandharが言ったように)

+0

画像を表示するためにimageviewを使用しているので意味がありません。ギャラリーをクリックすると私はこのチュートリアルを使用しました:http://saigeethamn.blogspot.com/2010/05/gallery-view-android-developer-tutorial.html –

+0

あなたはギャラリーを取得していますか? –

+0

はい私は私の質問で編集しようとしている絵のように見える描画可能な配列からイメージを引っ張っていますが、それらの順序を逆にしたいと思います。 –

0

は親切にレイアウトセクションのために、このXMLを試してみてください。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:gravity="center_vertical"> 

    <ImageView android:layout_alignParentTop="true" 
     android:id="@+id/ImageView01" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:src="@drawable/antartica1"/> 

    <Gallery 
     android:id="@+id/Gallery01" 
     android:layout_width="fill_parent" 
     android:layout_height="150dp" 
     android:layout_alignParentBottom="true" /> 

</RelativeLayout>