我正在创建一个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' }忘记在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 >
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。