Tôi cố gắng đạt tỷ lệ khung hình 16: 9 trên một chế độ xem với PercentRelativeLayout
.Cách sử dụng layout_aspectRatio trong PercentRelativeLayout?
Vì vậy, tôi đã đưa dòng này trong tập tin build.gradle tôi: compile 'com.android.support:design:23.0.1'
tôi sử dụng bố trí này:
<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>
vấn đề:
- Android Studio cảnh báo tôi với:
'layout_height' should be defined
cho sốImageView
. - Khi tôi chạy dự án của mình, tôi nhận được:
Error:(15) No resource identifier found for attribute 'layout_aspectRatio'
.
Vậy có vấn đề gì?
Tôi phải làm gì nếu tôi đang xây dựng cho API22 ?? Tôi không thể sử dụng quyền 23.1.0? bao gồm cả 'com.android.support: support-v4: 22.2.0' và' com.android.support: percent: 22.2.0' cho tôi lỗi tương tự. – ShahiM
@ShahiM: Tôi không hiểu tại sao bạn không thể sử dụng '23.1.0' với API22 - thực tế là tôi chắc chắn tôi đã tự làm như vậy. Như với appcompat, bạn có thể cần phải sử dụng các công cụ xây dựng phiên bản 23.0.0-23.0.2, nhưng điều đó không nên can thiệp vào targetSdkVersion của bạn. –
cảm ơn mẹo. sẽ thử điều đó. – ShahiM