0

我有一个基于 GridLayout 的自定义视图:

package com.mycompany.myapp;

...

public class GridLayoutForceSizeCells extends GridLayout
{
}

我已经为这个类定义了一个带有自定义属性的 xml:

<?xml version="1.0" encoding="utf-8" ?>
<resources>
    <declare-styleable name="GridLayoutForceSizeCells">
        <attr name="totalImages" format="integer" />
        <attr name="desiredColumnCount" format="integer" />
        <attr name="spacing" format="dimension" />
        <attr name="autoGenerate" format="boolean" />
    </declare-styleable>
</resources>

然后,我有一个使用这个的布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:wheel="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

 <com.mycompany.myapp.GridLayoutForceSizeCells
        xmlns:grid="http://schemas.android.com/apk/res/com.mycompany.myapp"
        android:padding="3dp"
        android:id="@+id/cellsGrid"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        grid:desiredColumnCount="20"
        grid:totalImages="0"
        grid:spacing="1dp"
        android:orientation="horizontal"/>

</LinearLayout>

我遇到的问题是,当我通过 gradle 风格更改 applicationId 时,自定义属性没有得到解决。我在 gradlew 帮助中读到应用程序包是使用 gradlew applicationId 条目解耦时用于 R 的应用程序包。所以,applicationId 不应该影响我的自定义属性包。但是,当我将 applicationId 设置为与 com.mycompany.myapp 不同的任何内容时,会出现错误,声称无法解析属性。

有没有人找到解决方案?

干杯。

4

1 回答 1

4

最后使用 xmlns:grid="http://schemas.android.com/apk/res-auto" 修复它,让它在布局文件中为我解析包,而不是完整的包名。

于 2015-01-19T23:24:14.437 回答