[英]No resource identifier found for attribute 'layout_behavior' in package
[英]Android Studio Error : No resource identifier found for attribute 'layout_behavior' in package 'com.example.parthp.myapplication'
我正在嘗試通過此鏈接進行教程: https : //developer.android.com/training/basics/firstapp/building-ui.html
當我按照教程中的描述編輯xml代碼時,它開始顯示錯誤(我在此問題的標題中已經提到)。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/activity_my">
我認為tools:showIn =“ @ layout / activity_my”有問題,因為當我刪除此文件后,一切正常。
PS:我是android的新手。
您將在包含content_my.xml
文件的布局文件夾中缺少activity_my
content_my.xml的簡單代碼將是
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</RelativeLayout>
您必須創建activity_my.xml
文件。
在代碼的最后一行中,您告訴編譯器xml布局(在問題中已描述)應該顯示在activity_my.xml
文件中。
創建activity_my.xml
文件,並將此布局包含到該文件中。
該文件可能類似於:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<include layout="@layout/content_main" />
</RelativeLayout>
content_main
將是您在問題中發布其xml代碼的文件的名稱。
我剛換
tools:showIn="@layout/activity_my"
至
tools:showIn="@layout/activity_my.xml"
現在可以了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.