Andy Dennie
Andy Dennie

Reputation: 6062

how to set ImageView width using Percent support lib and maintain aspect ratio?

Using the Android Percent Support Library, how can I set the width of an ImageView to a percentage of its containing PercentRelativeLayout, while scaling the height in such a way as to maintain the original aspect ratio?

Upvotes: 2

Views: 1086

Answers (1)

kris larson
kris larson

Reputation: 30985

I got this to work with version 23.0.0 support lib:

<?xml version="1.0" encoding="utf-8"?>
<android.support.percent.PercentRelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:src="@drawable/logo"
        app:layout_widthPercent="50%"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true" />

</android.support.percent.PercentRelativeLayout>

Upvotes: 3

Related Questions