我需要将BottomSheetBehavior
与ScrollView
一起使用,但它告诉我:
Unexpected namespace prefix "app" found for tag RelativeLayout
app:behavior_hideable="true"
app:behavior_peekHeight="80dp"
这是我的xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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">
<RelativeLayout 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">
<android.support.design.widget.AppBarLayout
android:id="@+id/ABLList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="end"
android:orientation="horizontal">
<ImageButton
android:id="@+id/imbDetail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|center_vertical"
android:layout_marginRight="10dp"
android:background="@null"
android:src="@drawable/ic_action_detail" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_OrderList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/ABLList"
android:scrollbars="vertical" />
</RelativeLayout>
<ScrollView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/layout_bottom_sheet_ListOrder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:background="@color/color_bottom_sheet"
android:gravity="top"
app:behavior_hideable="true"
app:behavior_peekHeight="80dp"
app:layout_behavior="@string/string_bottom_sheet_behavior">
<com.example.asheq.utils.TextViewJus
android:id="@+id/txtAddress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/text_marginTop"
android:gravity="right"
android:maxLines="5"
android:paddingLeft="@dimen/activity_vertical_margin"
android:paddingRight="@dimen/activity_vertical_margin"
android:textSize="@dimen/text_size"
android:textStyle="bold" />
<Button
android:id="@+id/btnSReport"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/txtCTime"
android:layout_marginTop="50dp"
android:text="@string/btnReport" />
</RelativeLayout>
</ScrollView>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/coordinatorOrder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
</android.support.design.widget.CoordinatorLayout>
答案 0 :(得分:8)
在布局中使用数据绑定时,此问题众所周知。
假设您要使用带有app:
前缀的某些数据绑定属性,然后仅添加xmlns:app...
就不够了。布局应为数据绑定布局,用<layout
标签包裹。
例如我导入了layout_toolbar_default.xml
,并使用app:toolbarTitle
指定了title
。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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"
>
<include
layout="@layout/layout_toolbar_default"
app:toolbarTitle="@{@string/app_name}"
/>
</LinearLayout>
这将显示错误Unexpected namespace prefix "app" found
。
因为您使用的是绑定属性,所以用<layout
标签包裹布局。
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<include
layout="@layout/layout_toolbar_default"
app:toolbarTitle="@{@string/app_name}"
/>
</LinearLayout>
</layout>
答案 1 :(得分:5)
我有同样的问题。只需将底页布局放入单独的文件中即可。并通过192.168.0.163:port/Service.svc
标记将其包含在主要布局中。
答案 2 :(得分:1)
如果要多次使用,请尝试在父布局中设置一次xmlns
命名空间。
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
在您的父CoordinatorLayout
中写一次此声明就足够了。
提示:使用多个布局和视图时,请尝试实现<include/>
属性。它将使您的代码清晰易读。
答案 3 :(得分:1)
对于在textView上遇到类似错误Unexpected namespace prefix “app” found
的人,您可能需要将TextView
更改为android.support.v7.widget.AppCompatTextView
。
答案 4 :(得分:1)
使用 android.support.v7.widget.LinearLayoutCompat
<template v-for="(item, index) of array">
<KeepAliveGlobal :key="`blah-blah-${index}`">
<YourComponent
:item="item"
:key="`your-component-${index}`"
/>
</KeepAliveGlobal>
</template>
答案 5 :(得分:0)
xmlns:app="http://schemas.android.com/apk/res-auto"
多次设定。 CoordinatorLayout
和RelativeLayout
都有。
删除RelativeLayout
中的一个。
在文件中声明一次就足够了。
答案 6 :(得分:0)
对于使用androidx的用户,如果您具有某些androidx视图的子视图,则它们也应该是androidx视图,以便能够识别应用程序名称空间前缀。例如,代替:
<ImageView/>
,您应该使用<androidx.appcompat.widget.AppCompatImageView/>
这不是有害的,如果您使用某些不支持的功能(例如ImageView的色调),它会为较低的api版本提供支持:)