volkangurbuz
volkangurbuz

Reputation: 259

images are too far into LinearLayout and HorizontalScrollView

how can i set the ranges of Images which are in the HorizontalScrollView

As you can see the images are not so close between themselves, i need them to be close.

This is my code for the HorizontalScrollView xml file:

 <HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="5dp"
android:id="@+id/hscrollview"
android:layout_weight="0.2">

<LinearLayout
    android:id="@+id/container"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:orientation="horizontal" />

This is what i have tried programmatically.

private ImageView getImageView(final Integer image, final int index) {

    imageView = new ImageView(getApplicationContext());
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    lp.setMargins(0, 0, 0, 0);

    imageView.setLayoutParams(lp);

    imageView.setScaleType(ImageView.ScaleType.FIT_XY);
    imageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            viewPager.setCurrentItem(index);

        }
    });

   imageView.setImageResource(image);

    return imageView;
}

enter image description here

Upvotes: 0

Views: 67

Answers (1)

johnrao07
johnrao07

Reputation: 6908

Try Changing the xml to

<HorizontalScrollView
android:layout_width="fill_parent"
android:background="@drawable/itemlistbg"
android:layout_height="wrap_content" >

    <LinearLayout
        android:id="@+id/itemlist"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"        
        android:gravity="center_vertical"
        android:orientation="horizontal"/>

</HorizontalScrollView>

Upvotes: 1

Related Questions