Android百分比支持库不产生结果

时间:2016-10-06 11:30:45

标签: android android-support-library android-percentrelativelayout

我正在尝试使用Android百分比支持库,以便我可以将imageVIews的边距设置为与屏幕大小成比例。这样做对imageViews的边距没有影响。这是我的XML文件:

<?xml version="1.0" encoding="utf-8"?>
<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="match_parent">

    <GridLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:background="@drawable/white">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column = "0"
            android:layout_row = "0"
            app:srcCompat="@drawable/a"
            android:id="@+id/a"
            app:layout_marginRightPercent="15%" />

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column = "1"
            android:layout_row = "0"
            app:srcCompat="@drawable/b"
            android:id="@+id/b"
            app:layout_marginRightPercent="15%"/>
    </GridLayout>
</android.support.percent.PercentRelativeLayout>  

我将依赖项包含在下面的build.gradle文件中。

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.2"
    defaultConfig {
        applicationId "com.abruzzi.alphabet"
        minSdkVersion 16
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.android.support:percent:24.2.1'
    testCompile 'junit:junit:4.12'
}

我做错了吗?任何帮助都将受到高度赞赏。

1 个答案:

答案 0 :(得分:0)

以下是我如何让我在android studio 2.2上工作,我有类似于urs的配置

def make(data):
    serializer = RouteOrderingSerializer(data=data)
    serializer.is_valid(raise_exception=True)
    serializer.save()

我点击了文件&gt; ProjectStructure&gt;应用&gt;属性我将我的构建工具版本更改为24.2.1并构建了项目但得到了包失败错误。我使用相同的方法将其更改回24.0.2并再次构建项目。奇迹般地,它有效......