In a project, I dynamically receive objects that contain in themselves some data and paths to images. I bring all the information to the activity , which includes the root layout ScrollView . At the end of this ScrollView I have a HorizontalScrollView on which I programmatically put the n-oe ImageView number, thus:

 final LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); for (int i = 0; i < hotel.getImages().size(); i++) { final int finalI = i; hotelImagesLayout.post(new Runnable() { @Override public void run() { ImageView hotelImage = new ImageView(context); hotelImage.setAdjustViewBounds(true); hotelImage.setLayoutParams(params); Picasso.with(context) .load(hotel.getImages().get(finalI)) .placeholder(R.drawable.place_holder) .transform(transformation) .into(hotelImage); hotelImagesLayout.addView(hotelImage); } }); } 

Pictures are laid normally, horizontally, too, everything is scrolling ok, but! I need the first picture to stretch across the entire screen, to the size of the device, and not to retain its previous width and size.

Here is the markup where I put the images:

  <HorizontalScrollView android:id="@+id/horizontalLayout" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_below="@+id/regionAndName" android:layout_marginTop="10dp"> <LinearLayout android:id="@+id/hotelImagesLayout" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="horizontal" /> </HorizontalScrollView> 

How to make the image stretch to the width of the screen in horizontalScrollView ? I tried to play with scaleType, but something did not help.

    2 answers 2

    You will have to calculate the height and width programmatically.
    That is, after loading the image, you need to set the ImageView width and height corresponding to the size of your screen.

    • Thanks, I'll try to do it. But in theory, I just need to calculate the width, and the height is already scaled relative to it - Android Android
    • Yes, this decision helped. Thank you - Android Android

    Try setting the width and height of match_parent in the code for ImageView

    • did just that - did not help - Android Android
    • Hmm, my answer is essentially the same as that of @metalurgus, but for some reason, they hit it: D - Crok
    • I did not give a minus. But your answers are in no way similar, especially since in the question I showed with the code that programmatically match_parent is set - Android Android
    • Try to write more detailed answers. Explain what is the basis of your statement? - Nicolas Chabanovsky
    • @Crok, your answer is absolutely not like mine. match_parent will work only if the guy has a certain size. The container that lies in the ScrollView does not have a specific size. Try it yourself, and make sure it doesn't work - Vladyslav Matviienko