Using the gallery to scroll between views

I follow the Android Gallery guide ( http://developer.android.com/guide/tutorials/views/hello-gallery.html ), but instead of simple images, I would like to be able to move horizontally to a new new screen, such as LinearLayout. An idea is a kind of tabulation behavior, but the user can scroll through the screens.

I created a gallery, created a GalleryAdapter, which extends from the BaseAdapter and the getItem () method. I am trying to return a complex view:

@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;
}

In the above example, it will work if I use ImageView, but it fails if I use a more complex view like scrollView loaded from resources.

Any idea why? The exception is:

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)

Thanx Sven

+3
2

, ) , ScrollView b), , getView. , getLayout XmlResourceParser a ScrollView. :

:

inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

.

getView:

View view = inflater.inflate(R.layout.main, parent, false);
return view;

layout_main ScrollView, .

+2

, - . , ? .

0

Source: https://habr.com/ru/post/1754894/


All Articles