It is possible to add a ImageView inside a XML LinearLayout with the 15% of the width of the screen of width and also exactly the same height?
I tried it with this dialog code which is being displayed when a user clicks on a marker on the map:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/custom_info_bubble"
android:orientation="vertical">
.
. [some more content here]
.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="100">
<ImageView
android:id="@+id/favorite"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:adjustViewBounds="true"
android:layout_gravity="center_horizontal"
android:layout_weight="15"
android:layout_marginEnd="5dp" />
</LinearLayout>
</LinearLayout>
But is has two problems:
Problem 1: android:layout_weight="15" makes 15% of the width of the dialog, not of the screen, and that's a huge problem, because the dialog has some times more or less width depending of its content.
Problem 2: the width is 15% ok but the height is the real height of the image. I don't know how to make it to have exactly the same height than it's width. Its a square image, so I tried make it respecting its proportions putting wrap_content on height and adjustViewBounds=true but it didn't work.
Problem 3: the ImageView is not being centered, is aligned to the left. I need it centered.
How can this be achieved with XML instead of Java code?