我尝试在视图上实现 16:9 的纵横比PercentRelativeLayout https://developer.android.com/reference/android/support/percent/PercentRelativeLayout.html.
所以我将这一行放入我的 build.gradle 文件中:compile 'com.android.support:design:23.0.1'
我使用这个布局:
<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="wrap_content">
<ImageView
android:layout_width="match_parent"
app:layout_aspectRatio="178%"
android:scaleType="centerCrop"/>
</android.support.percent.PercentRelativeLayout>
问题:
- Android Studio 警告我:
'layout_height' should be defined
为了ImageView
.
- 当我运行我的项目时,我得到:
Error:(15) No resource identifier found for attribute 'layout_aspectRatio'
.
那么出了什么问题呢?
有了正确的依赖,你仍然会收到警告
应该定义“layout_height”
我使用 android:layout_height="0dp" 或 android:layout_width="0dp" 来避免它。
<View
android:layout_height="0dp"
android:layout_width="0dp"
app:layout_aspectRatio="75%"
app:layout_widthPercent="100%"
/>
你甚至可以使用 android:layout_height="wrap_content" 以防内容大于layout_aspectRatio
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)