我遵循Android圖庫教程(http://developer.android.com/guide/tutorials/views/hello-gallery.html),但不是簡單的圖像,我希望能夠水平移動到一個完整的新屏幕,例如,一個LinearLayout。這個想法是一種標籤行爲,但用戶可以通過屏幕滑動。使用圖庫在視圖之間滑動
我創建了一個庫,創建了從BaseAdapter和爲getItem()方法擴展我嘗試返回複雜視圖GalleryAdapter:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
/*ImageView i = new ImageView(this.c);
i.setImageResource(R.drawable.login);
i.setLayoutParams(new Gallery.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
i.setScaleType(ImageView.ScaleType.FIT_XY);
return i;*/
ScrollView view = (ScrollView)this.c.getResources().getLayout(R.layout.main);
return view;
}
在上面的例子中,它會工作,如果我使用一個ImageView,但是一旦我使用像資源加載的scrollView這樣更復雜的視圖,它就會失敗。
任何想法爲什麼?唯一的例外是:
07-15 13:47:36.498: ERROR/AndroidRuntime(446): java.lang.ClassCastException: android.content.res.XmlBlock$Parser
07-15 13:47:36.498: ERROR/AndroidRuntime(446): at de.flavor.myviews.GalleryAdapter.getView(GalleryAdapter.java:44)
07-15 13:47:36.498: ERROR/AndroidRuntime(446): at android.widget.AbsSpinner.onMeasure(AbsSpinner.java:192)
07-15 13:47:36.498: ERROR/AndroidRuntime(446): at android.view.View.measure(View.java:8171)
07-15 13:47:36.498: ERROR/AndroidRuntime(446): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
07-15 13:47:36.498: ERROR/AndroidRuntime(446): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
07-15 13:47:36.498: ERROR/AndroidRuntime(446): at android.view.View.measure(View.java:8171)
07-15 13:47:36.498: ERROR/AndroidRuntime(446): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
07-15 13:47:36.498: ERROR/AndroidRuntime(446): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
07-15 13:47:36.498: ERROR/AndroidRuntime(446): at android.view.View.measure(View.java:8171)
07-15 13:47:36.498: ERROR/AndroidRuntime(446): at android.view.ViewRoot.performTraversals(ViewRoot.java:801)
07-15 13:47:36.498: ERROR/AndroidRuntime(446): at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
感謝名單 斯文