简体   繁体   English

将图像调整为LinearLayout和Horizo​​ntalScrollView

[英]Resizing images into LinearLayout and HorizontalScrollView

how can i set the images which are in the HorizontalScrollView 我如何设置在Horizo​​ntalScrollView中的图像

As you can see the images are so much wide, i need them to be of normal size. 如您所见,图像是如此之宽,我需要它们具有正常的尺寸。

This is my code for the HorizontalScrollView xml file: 这是我的HorizontalScrollView xml文件的代码:

    <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" />
</HorizontalScrollView>

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

在此处输入图片说明

Change 更改

imageView.setScaleType(ImageView.ScaleType.FIT_XY);

to

imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM