如何使用Percent支持lib设置ImageView宽度并保持宽高比?

时间:2015-09-14 21:00:16

标签: android android-layout android-percentrelativelayout android-percent-library percent-support-library

使用Android百分比支持库,如何将ImageView的宽度设置为包含PercentRelativeLayout的百分比,同时缩放高度以保持原始宽高比?

1 个答案:

答案 0 :(得分:3)

我得到了这个版本23.0.0支持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>