我有一个布局,左侧有一组小部件,右侧有一些小部件.
现在我想在中间放置一个按钮,下面是两个文本视图(一个在左边,另一个在右边).
我得到一个错误("重复属性")与以下代码:
android:layout_centerInParent="true"
android:layout_below="@id/text_left"
android:layout_below="@id/text_right"
Run Code Online (Sandbox Code Playgroud)
我怎么解决这个问题?
谢谢.
liv*_*ove 42
如果您在不同的布局中具有相同的xmlns属性,也会发生此错误消息.
在这种情况下,xmlns:tools在布局和ConstraintLayout中重复.从其中一个布局中删除它应该可以解决问题.
<layout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable
name="item"
type="com.myapp.SearchSettings" />
</data>
<android.support.constraint.ConstraintLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" <-- remove this line
(it is already in layout tag)
Run Code Online (Sandbox Code Playgroud)
vik*_*mar 29
对于那些,接受的答案不起作用,并且通过任何更改您正在使用 android数据绑定,如果某些属性在父标签和子标签中出现两次,则可能会出现这种错误。在下面的示例中,在parent和childandroid:layout_width="match_parent" android:layout_height="wrap_content"中使用了两次。
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<data>
<variable
name="pdpDescriptionViewModel"
type="com.tottus.ui.productdescription.model.PdpDescriptionViewModel" />
</data>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</LinearLayout>
</layout>
Run Code Online (Sandbox Code Playgroud)
要解决此问题,请从父级或子级中删除重复属性,它应该可以工作。
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable
name="pdpDescriptionViewModel"
type="com.tottus.ui.productdescription.model.PdpDescriptionViewModel" />
</data>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</LinearLayout>
</layout>
Run Code Online (Sandbox Code Playgroud)
pro*_*007 14
你正在设置layout_below两次.
如果你想有问题的布局低于这两个的,尝试的两个结合text_left,并text_right进入一个布局,然后使用layout_below和分配给它你给它包含的组合布局的名称text_left和text_right.
| 归档时间: |
|
| 查看次数: |
19557 次 |
| 最近记录: |