开发者社区> 问答> 正文

无法在Android Studio中解析符号“ coordinatorlayout”

我正在创建一个android应用并使用坐标布局,但是却遇到此错误。已经在build.gradle文件和activity_main.xml文件中添加了坐标布局。另一个类仅在此单行代码中存在问题时才能正常工作。是否有其他方法可以将坐标布局替换为任何其他布局设计。

这是我的MainActivity.java文件,已经导入了设计布局。在activity_main.xml文件中也是如此。

MainActivity.java

import android.net.Uri; import android.os.Bundle; import android.support.design.widget.CoordinatorLayout; import android.support.design.widget.Snackbar; import android.support.design.widget.TabLayout;

public class MainActivity extends AppCompatActivity { ... ... @BindView(R.id.image_preview) ImageView imagePreview;

@BindView(R.id.tabs)
TabLayout tabLayout;

@BindView(R.id.viewpager)
ViewPager viewPager;

@BindView(R.id.coordinator_layout)  //here I'm getting error 'cannot resolve symbol 'coordinate layout''
CoordinatorLayout coordinatorLayout;
...
...

} activity_main.xml

的build.gradle apply plugin: 'com.android.application' android { compileSdkVersion 27 defaultConfig { applicationId "com.example.app" minSdkVersion 24 targetSdkVersion 27 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.android.support:appcompat-v7:27.0.2' implementation 'com.android.support.constraint:constraint-layout:1.0.2' implementation 'com.android.support:design:27.0.2' implementation 'com.android.support:support-v4:27.0.2' implementation 'android.arch.navigation:navigation-fragment:1.0.0-alpha05' implementation 'android.arch.navigation:navigation-ui:1.0.0-alpha05' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.1' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' }

展开
收起
小六码奴 2019-10-03 19:37:33 1075 0
1 条回答
写回答
取消 提交回答
  • 忘记在activity_main.xml布局文件中为CoordinatorLayout布局分配id

    只需添加android:id="@+id/coordinator_layout" id在你的CoordinatorLayout中,它将工作

    试试这个

    < ?xml version = " 1.0 " encoding = " utf - 8 " ? >

    < android.support.design.widget.CoordinatorLayout xmlns: android = " http://schemas.android.com/apk/res/android "

    xmlns:应用= " http://schemas.android.com/apk/res-auto "

    xmlns:工具= " http://schemas.android.com/tools "

    android: layout_width = " match_parent "

    android: layout_height = " match_parent "

    android: id =“@ + id / coordinator_layout”

    工具:上下文= " .MainActivity " >

    < android.support.design.widget.AppBarLayout

    android: layout_width = " match_parent "

    android: layout_height = " wrap_content "

    android:主题= " @style / AppTheme.AppBarOverlay " >

    < android.support.v7.widget.Toolbar

    android: id =“@ + id /工具栏”

    android: layout_width = " match_parent "

    android: layout_height = " ? attr / actionBarSize”

    android:背景= " @android:颜色/白”

    应用:popupTheme = " @style / AppTheme。PopupOverlay " / >

    < / android.support.design.widget.AppBarLayout >

    <包括布局= " @layout / content_main " / >

    < / android.support.design.widget.CoordinatorLayout >

    2019-10-09 15:59:56
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
58同城Android客户端Walle框架演进与实践之路 立即下载
Android组件化实现 立即下载
蚂蚁聚宝Android秒级编译——Freeline 立即下载