2016-06-29 24 views
0

我正在嘗試使用PercentRelativeLayout來獲取我的小部件的比率。即使我更新了依賴關係,似乎Android Studio也不會識別該庫。PercentRelativeLayout不工作

這裏是我的gradle這個

android { 
compileSdkVersion 23 
buildToolsVersion "23.0.3" 

defaultConfig { 
    applicationId "com.cobaltsign.androidwidget" 
    minSdkVersion 21 
    targetSdkVersion 23 
    versionCode 1 
    versionName "1.0" 
} 
buildTypes { 
    release { 
     minifyEnabled false 
     proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
    } 
}} 

dependencies { 
compile fileTree(dir: 'libs', include: ['*.jar']) 
testCompile 'junit:junit:4.12' 
compile 'com.android.support:appcompat-v7:23.4.0' 
compile 'joda-time:joda-time:2.9.3' 
compile 'com.squareup.picasso:picasso:2.5.2' 
compile 'com.google.android.gms:play-services-appindexing:9.0.2' 
compile 'com.makeramen:roundedimageview:2.2.1'} 

Any idea ? 

回答

1

你必須在你的build.gradle導入compile 'com.android.support:percent:23.3.0'。看看這個例子:

<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"> 
<ImageView 
    app:layout_widthPercent="50%" 
    app:layout_heightPercent="50%" 
    app:layout_marginTopPercent="25%" 
    app:layout_marginLeftPercent="25%"/> 

+0

難道我的回答幫助你@Huiculescu –

+0

現在只需添加它,它沒有任何變化。 我還沒有創建「app:layout_aspectRatio」屬性,我需要。 我也在xml中添加了xmlns:app =「http://schemas.android.com/apk/res-auto」到佈局中 –

+0

你可以給我什麼你爲'app:layout_aspectRatio'寫的東西嗎? –

0

在我來說,我不得不用app:layout_widthPercent="100%"代替android:layout_width="match_parent"爲了有比像1:2與這一個app:layout_aspectRatio="200%"

合力佈局是:

<FrameLayout 
    android:background="@color/black_25" 
    app:layout_aspectRatio="200%" 
    app:layout_widthPercent="100%" />