我試圖在PercentRelativeLayout
的視圖上實現16:9的寬高比。如何在PercentRelativeLayout中使用layout_aspectRatio?
所以我已經把這個線在我的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'
。
那麼,怎麼了?
如果我正在爲API22構建,我該怎麼辦?我不能使用23.1.0的權利?包括'com.android.support:support-v4:22.2.0'和'com.android.support:percent:22.2.0'給了我同樣的錯誤。 – ShahiM
@ShahiM:我不明白你爲什麼不能在API22中使用'23.1.0'--事實上,我很肯定我自己是這麼做的。與appcompat一樣,您可能確實需要使用構建工具版本23.0.0-23.0.2,但這不應該干擾您的targetSdkVersion。 –
感謝您的提示。會嘗試一下。 – ShahiM