'Resize Layout to ImageView real size
I have a FrameLayout inside a ConstraintLayout.
The FrameLayout is constrained to different elements of the screen and has no hardcoded size.
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/fragment_raumauswertung"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:backgroundTint="#883B3B"
tools:context=".RoomActivity">
<FrameLayout
android:id="@+id/frameLayout"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@+id/text_wall3"
app:layout_constraintEnd_toStartOf="@+id/text_wall2"
app:layout_constraintStart_toEndOf="@+id/text_wall4"
app:layout_constraintTop_toBottomOf="@+id/text_wall1" />
With
fragmentBinding?.frameLayout?.addOnLayoutChangeListener{...}
I'm waiting for the FrameLayout to get his final size to set an ImageView by using .setImageBitmap(bitmap).
After the ImageView was set i want to resize the FrameLayout to the size of the real size of the ImageView. I try to get the height the FrameLayout should be set by either:
imageView.height
imageView.measuredHeight
imageView.drawable.intrinsicHeight
But none of this values is correct. There is always a white border at the top and bottom.
Why i need it to be the exact same size:
I created a 2D Floorplan of a room which is drawn into a Bitmap.
Inside this Floorplan are points which are clickable.
I added an OnTouchListener to the FrameLayout to compare the x&y pixel of the TouchEvent to the x&y pixel of my Floorplan. If it matches a popup opens.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
