我正在尝试使用 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'
}
有什么我做错了吗?任何帮助将不胜感激。