Search code examples
androidandroid-layoutimageviewandroid-linearlayouthorizontalscrollview

Image not completely showing in HorizontalScrollView


I'm using HorizontalScrollView to create a horizontal image gallery but for some reason the first image is not completely being shown and I cannot scroll left anymore and is cropped however when I rotate the device it shows it fine. I tried playing with fill_parent and wrap_content both in my linearlayout and horizontalscroll view but non worked. enter image description here Here is my xml:

<HorizontalScrollView
    android:id="@+id/horizontalScroll"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:fillViewport="true"
    android:measureAllChildren="false"
    android:layout_marginLeft="15dp"
    android:layout_marginRight="15dp"
    android:layout_centerHorizontal="true"
    android:scrollbars="none"
   android:layout_below="@id/image" >
    <LinearLayout android:id="@+id/gallery"
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center_horizontal">
    </LinearLayout>
</HorizontalScrollView>

and here is my code:

 myGallery = (LinearLayout) getActivity().findViewById(R.id.gallery);
    for (int i = 0; i < images.size(); i++) {
        ImageView imageView = new ImageView(getActivity().getApplicationContext());
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        Picasso.with(getActivity()).load(images.get(i)).placeholder(R.drawable.ic_photos).resize(150,  150).into(imageView);
        myGallery.addView(imageView);
    }

Solution

  • I added margin_left to my LinearLayout and it shows it now. I don't know if this is hacky or not but it worked for me