nirhart / ParallaxScroll

Parallax ScrollView and ListView for Android
MIT License
848 stars 187 forks source link

How to add an imageview as Header and set its Width and Height #45

Open victorguilhermeo opened 9 years ago

victorguilhermeo commented 9 years ago

I've been trying for ages to figure this out, how to add an imageview on code and set its width to match_parent and height to wrap_content. I've tried many things but I keep getting class cast exception

    ParallaxListView pListView = (ParallaxListView) getActivity().findViewById(R.id.prods_list);

    ImageView iv = new ImageView(getActivity());
    LinearLayout.LayoutParams parms = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    iv.setLayoutParams(parms);
    iv.setAdjustViewBounds(true);

    RequestCreator picassoRequest = Picasso.with(getActivity()).load("http://www.colonialgeneral.com/images/convenience-store.jpg").error(R.drawable.error);
    picassoRequest.into(iv);

and my fragment_list.xml

<com.nirhart.parallaxscroll.views.ParallaxListView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/prods_list" android:layout_width="match_parent" android:layout_height="match_parent" app:parallax_factor="1.9" tools:context=".MainActivity$FragmentProds" />

nirhart commented 9 years ago

Probably because your ImageView is not in LinealLayout, can you provide the class cast exception error log ?