android - layout_widthPercent加载dependencies后还是不能使用,是什么原因?
阿神
阿神 2017-04-18 09:04:22
0
1
725

为什么添加依赖后,还是不能使用layout_widthPercent/layout_heightPercent?
依赖:

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:percent:24.2.1'
    compile 'com.android.support:appcompat-v7:24.2.1'
    testCompile 'junit:junit:4.12'
}

使用layout_widthPercent

<?xml version="1.0" encoding="utf-8"?>
<android.support.percent.PercentFrameLayout
    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">
    <Button
        android:id="@+id/button1"
        android:text="Button1"
        android:layout_gravity="left|top"
        android:layout_widthPercent="50%"
        android:layout_heightPercent="50%"/>
</android.support.percent.PercentFrameLayout>

告警:

 No resource identifier found for attribute 'layout_widthPercent' in package 'android'

阿神
阿神

闭关修行中......

reply all(1)
阿神

Thanks for the invitation. I have never used android.support.percent.PercentFrameLayout, but from the package name I can probably tell that it is provided by support and is not a Layout supported in native environments. So the xml code should be as follows:

<?xml version="1.0" encoding="utf-8"?>
<android.support.percent.PercentFrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:appCompat="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Button
        android:id="@+id/button1"
        android:text="Button1"
        android:layout_gravity="left|top"
        appCompat:layout_widthPercent="50%"
        appCompat:layout_heightPercent="50%"/>
</android.support.percent.PercentFrameLayout>

Pay attention to the definition and reference of appCompat.
Finally, any Layout (or View) that can be referenced in the code or layout-xml can be used normally. If an error is reported, it means the usage is wrong.

p.s. If the answer is wrong, please downvote this answer (because I have not specifically used the PercentFrameLayout).

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template