【问题标题】:how to set ImageView width using Percent support lib and maintain aspect ratio?如何使用百分比支持库设置 ImageView 宽度并保持纵横比?
【发布时间】:2015-09-14 21:00:16
【问题描述】:
使用 Android Percent Support Library,如何将 ImageView 的宽度设置为其包含 PercentRelativeLayout 的百分比,同时以保持原始纵横比的方式缩放高度?
【问题讨论】:
标签:
android
android-layout
android-percentrelativelayout
android-percent-library
percent-support-library
【解决方案1】:
我让它与版本 23.0.0 支持库一起工作:
<?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>