应指定Android PercentRelativeLayout宽度和高度

时间:2016-08-25 08:41:50

标签: android android-percentrelativelayout android-percent-library

我正在尝试使用android.support.percent.PercentRelativeLayout

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.percent.PercentRelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white">

    <ImageView
                app:layout_widthPercent="70%"
                app:layout_aspectRatio="1000%"
                app:layout_marginTopPercent="15%"
                android:layout_centerHorizontal="true"
                android:src="@drawable/logo"/>
    </android.support.percent.PercentRelativeLayout>
</ScrollView>

Android Studio给了我错误:

"layout_height should be specified
"layout_width should be specified"

Project is building now, but studio shows errors and do not suggest autocompletion when I start typing "percent..."

我做错了什么?

来自官方网站的

Here is示例,为什么它不起作用?

1 个答案:

答案 0 :(得分:2)

这里回答的问题是:PercentRelativeLayout - layout_width missing warning

基本上; PercentRelativeLayout会忽略宽度和高度,但您需要将它们设置为0dp,因为Android Studio希望它们在此处。