gpt4 book ai didi

android - 如何通过 xml 为自定义 View 传递重力属性?

转载 作者:太空狗 更新时间:2023-10-29 16:36:41 26 4
gpt4 key购买 nike

我正在尝试弄清楚如何通过 xml 为自定义 View 传递 android:gravity

此处发布的解决方案 (https://stackoverflow.com/a/3441986/413254) 表示将 android:gravity 属性添加到其他 attr。

当我这样做时,我会收到一条警告:

/Users/greg/dev/company/mobile/my_app/app/src/main/res/values/colors.xml

Error:Attribute "android:gravity" has already been defined Error:Execution failed for task ':app:processStagingDebugResources'.

com.android.ide.common.internal.LoggedErrorException: Failed to run command: /Users/greg/dev/android-sdk/sdk/build-tools/21.0.2/aapt package -f --no-crunch -I /Users/greg/dev/android-sdk/sdk/platforms/android-21/android.jar -M /Users/greg/dev/company/mobile/myapp/app/build/intermediates/manifests/full/staging/debug/AndroidManifest.xml -S /Users/greg/dev/company/mobile/myapp/app/build/intermediates/res/staging/debug -A /Users/greg/dev/company/mobile/myapp/app/build/intermediates/assets/staging/debug -m -J /Users/greg/dev/company/mobile/myapp/app/build/generated/source/r/staging/debug -F /Users/greg/dev/company/mobile/myapp/app/build/intermediates/res/resources-staging-debug.ap_ --debug-mode --custom-package com.company.vendorreviews -0 apk --output-text-symbols /Users/greg/dev/company/mobile/myapp/app/build/intermediates/symbols/staging/debug Error Code: 1 Output: /Users/greg/dev/company/mobile/myapp/app/build/intermediates/res/staging/debug/values/values.xml:165: error: Attribute "android:gravity" has already been defined

我的 colors.xml 文件?

values.xml 的第 165 行是

<declare-styleable name="StackedTextView">
<attr format="integer" name="android:gravity"/>
<attr format="string" name="line1"/>
<attr format="string" name="line2"/>
<attr format="dimension" name="line1_textSize"/>
<attr format="dimension" name="line2_textSize"/>
</declare-styleable>

android:gravity 在多个组中多次出现。主题、FlowLayout(我包含的库)、LinearLayoutCompat 等。

编辑:更新了错误消息。

最佳答案

通过写作:

<attr format="integer" name="android:gravity"/>

你正在引入整数格式的新属性android:gravity,当然android:gravity已经在系统中定义了,所以你需要将其更改为:

<attr name="android:gravity"/>

关于android - 如何通过 xml 为自定义 View 传递重力属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27047346/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com