Insert custom zoom content with drawability

I have a ListView with custom elements defined in relativeLayout, which includes an imageView with android:layout_width="match_parent"and android:layout_height="wrap_content"and a custom vector that can be used as a source, which looks like this:

+-------------------------------------------+
+    solid area              | some picture +
+-------------------------------------------+

The problem is that when I switch to landscape mode, the image becomes scaled (to handle the parent width), but at the same time maintaining the aspect ratio, the height increases.

Ideally, I would like to define a Content Inset (as I know it is from iOS), so that the solid area above is stretched to fit the new width, and the "some picture" area is supported with the same aspect ratio. In general, the scaling will happen this way, that the height of the image (and therefore the entire listView element) will be preserved.

+4
source share
1 answer

You can stretch a solid region using LinearLayoutwith the weight of the layout in the width of the child. To do this job, you must assign a fixed width ImageView.

, adjustViewBounds ImageView .

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="?android:attr/listPreferredItemHeight"
    android:orientation="horizontal">

    <!-- this can be any view or view group, the layout params are the important part-->
    <View
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        ...
        />

    <!-- set this to an absolute width that will be the same for portrait & landscape -->
    <ImageView
        android:layout_width="240dp"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        ...
        />

</LinearLayout>
+1

Source: https://habr.com/ru/post/1665450/


All Articles