0

I am trying to use the Android percent support library so that I can set the margins of my imageVIews proportional to the screen size. Doing so has no effect on the margins of the imageViews. Here is my XML file:

<?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>  

I included the dependency to my build.gradle file below.

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'
}

Is there something I am doing wrong? Any help would be highly appreciated.

Onik
  • 19,396
  • 14
  • 68
  • 91
abruzzi26
  • 159
  • 1
  • 10
  • first change this `buildToolsVersion "24.0.2"` to `buildToolsVersion "24.2.1"`. You have to use same version for `build` and `support`. – Harshad Pansuriya Oct 06 '16 at 11:35
  • Doing this gave me an error "Failed to find Build Tools revision 24.2.1". Then trying to install this gave me another error "All packages are not available for download! The following packages are not available: -Package id build-tools;24.2.1". Any other ideas? – abruzzi26 Oct 06 '16 at 12:25
  • Try using percentage layout inside gridlayout. – Kshitij Jain Oct 06 '16 at 12:26

1 Answers1

0

Here is how i got mine to work on android studio 2.2, i had a similar configuration as urs

android {
compileSdkVersion 24
buildToolsVersion '24.0.2'
defaultConfig {
    applicationId "com.software.praescient.socialdev"
    minSdkVersion 12
    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(include: ['*.jar'], dir: 'libs')
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'
testCompile 'junit:junit:4.12'
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha8'
compile 'com.android.support:percent:24.2.1'
  }

I clicked on File>ProjectStructure>App>Properties i changed my Build tools version to 24.2.1 and built the project but got the package failed error. I change it back to 24.0.2 using the same approach and the built the project again. Miraculously, it worked...

Mueyiwa Moses Ikomi
  • 1,069
  • 2
  • 12
  • 26