如何使用layout_aspectRatio在PercentRelativeLayout? [英] How to use layout_aspectRatio in the PercentRelativeLayout?

查看:322
本文介绍了如何使用layout_aspectRatio在PercentRelativeLayout?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尽力达成一个16:上用的 PercentRelativeLayout

I try to achieve a 16:9 aspect ratio on a view with the PercentRelativeLayout.

所以,我已经把这个线在我的build.gradle文件:编译com.android.support:design:23.0.1

So I have put this line in my build.gradle file: 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的工作室提醒我:'layout_height应定义的ImageView

  • 当我跑我的项目我有:错误:(15)未找到属性layout_aspectRatio资源标识符

  • Android Studio warn me with: 'layout_height' should be defined for the ImageView.
  • When I run my project I got : Error:(15) No resource identifier found for attribute 'layout_aspectRatio'.

那么,什么是错的?

推荐答案

看来你使用,企图包含的%的支持库

It appears you're using the wrong dependency in an attempt to include the Percent Support Library.

正确的一个(最新版)是:

The correct one (and latest version) is:

com.android.support:percent:23.1.0

在换句话说,声明的依赖性看起来应该像这样在你的文件的gradle:

In other words, the declared dependency should look like this in your gradle file:

compile 'com.android.support:percent:23.1.0'

这篇关于如何使用layout_aspectRatio在PercentRelativeLayout?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆