我已經按照教程創建了一個帶有imageview的圖庫。我想要做的就是將圖庫放置在底部,並將圖像放置在圖像上方,但是當我在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;
}
是啊,我也獲得同樣的問題,如果ImageView的是上面和畫廊如下。 – 2012-01-27 05:34:34
你能告訴我們這段代碼:com.appinfluence.fanapp.v1.Photos.onCreate(Photos.java:36) – 2012-01-27 05:45:30
它已經存在 – 2012-01-27 06:06:47