Android-Image-Slider icon indicating copy to clipboard operation
Android-Image-Slider copied to clipboard

How to have wrap_content height instead of fixed height?

Open hkchakladar opened this issue 6 years ago • 5 comments

I have used wrap_content height. But it doesn't show the image. I want to use the wrap_content height, so that the slider is shown based on image retrieved image size from url.

hkchakladar avatar Oct 15 '19 17:10 hkchakladar

Did you find any solution?

yilmaz-gokhan avatar Nov 28 '19 18:11 yilmaz-gokhan

Any Solution to this?

i-m-aman avatar Dec 12 '19 22:12 i-m-aman

@i-m-aman @yilmaz-gokhan I've used with fixed ratio and serving the images in that fixed ratio, where I control the source.

hkchakladar avatar Jan 31 '20 20:01 hkchakladar

Using ConstraintLayout as a parent view to control the ratio:

Here is the xml example:

<android.support.constraint.ConstraintLayout
  android:layout_width="match_parent"
  android:layout_height="wrap_content">

  <com.smarteist.autoimageslider.SliderLayout
     android:layout_width="0dp"
     android:layout_height="0dp"
     app:layout_constraintDimensionRatio="H,2:1" //2=ratio of height, 1=ratio of width
     app:layout_constraintEnd_toEndOf="parent"
     app:layout_constraintStart_toStartOf="parent"
     app:layout_constraintTop_toTopOf="parent"/>

 </android.support.constraint.ConstraintLayout>

andyleekp avatar Apr 15 '20 09:04 andyleekp

I like your answer @andyleekp, the only thing that can be improved, if needed, is to calculate the aspect ratio dynamically for each image (if images are what drives heights for each page of the slider).

abdurahmanadilovic avatar Feb 16 '21 14:02 abdurahmanadilovic