【问题标题】:How can I see the xml DrawerLayout file in android studio如何在 android studio 中查看 xml DrawerLayout 文件
【发布时间】:2015-05-09 22:22:07
【问题描述】:

我正在 android studio 上创建 XML 抽屉布局文件,但无法在 android studio 上预览我收到此错误我该如何解决问题

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">


<LinearLayout
    android:fitsSystemWindows="true"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="#ff6600"
    android:paddingRight="@dimen/activity_horizontal_margin"

    tools:context="br.com.appingles.Tela2" >

    <include android:id="@+id/app_bar" layout="@layout/app_bar"/>

    <TextView
        android:id="@+id/assertosTela2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="30dp"
        android:layout_marginTop="20dp"
        android:text="TextView" />

    <TextView
        android:id="@+id/perguntaTela2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="28dp"
        android:text="TextView" />

    <Button
        android:id="@+id/button2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="35dp"
        android:onClick="button2"
        android:text="Button2" />

    <Button
        android:id="@+id/button3"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="27dp"
        android:onClick="button3"
        android:text="Button3" />

    <Button
        android:id="@+id/button4"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="25dp"
        android:onClick="button4"
        android:text="Button4" />

    <Button
        android:id="@+id/button1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="58dp"
        android:onClick="button1"
        android:text="Button1" />

</LinearLayout>

<fragment
    android:id="@+id/fragment_navigation_drawer"
    android:layout_width="@dimen/nav_dr"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    app:layout="@layout/fragment_navigation_drawer"
    android:name="br.com.appingles.NavigationDrawerFragment"
    tools:layout="@layout/fragment_navigation_drawer"
    />

android {
compileSdkVersion 22
buildToolsVersion '19.1.0'

defaultConfig {
    applicationId "br.com.appingles"
    minSdkVersion 17
    targetSdkVersion 22
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:support-v4:22.1.1'
compile 'com.android.support:appcompat-v7:22.1.1'
compile 'com.android.support:recyclerview-v7:22.1.1'

}

我收到此错误:

渲染问题 找不到以下类:android.support.v4.widget.Drawer Layout (Fix Build Path, Create Class) 提示:尝试构建项目。

【问题讨论】:

  • 这个?编译'com.android.support:support-v4:22.1.1'
  • 在你的 xml 文件中我没有看到抽屉。
  • 第一次入栈,忘记添加完整代码,现在编辑添加完毕。

标签: android xml android-studio drawerlayout


【解决方案1】:

layout.xml 的父级(最顶层元素)必须是 android.support.v4.widget.DrawerLayout,如下所示:

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000"
    tools:context="mainMenu.MainExpandActivity">

如果一切正常,如果仍然没有显示预览,则编译并构建您的项目,然后尝试。

根据Android developer's page

主内容视图(上面的 FrameLayout)必须是 DrawerLayout 中的第一个子视图,因为 XML 顺序意味着 z 顺序,并且抽屉必须位于内容之上。


编辑

首先你需要添加外部Jar

在android studio中转到文件->项目结构->模块->依赖项->+符号->库依赖项。

现在搜索支持库。你会发现类似 com.android.support:support-v13

现在,选择名为 support-v13 的 Jar 文件(无论版本是什么),然后单击“确定”。

编辑#2

调色板没有立即显示您的DrawerLayout。其实,这是一种正常的行为。毕竟,Palette 只显示静态单层视图,而DrawerLayout 是一个复杂的ViewGroup,它具有多层:抽屉和内容。同时,DrawerLayout 是一个动态视图,其效果只能在设备或模拟器上看到。因此,请随意运行加载此布局的 Activity,您将看到包含 DrawerLayout 的布局的效果

【讨论】:

  • 第一次入栈,忘记添加完整代码,现在编辑添加完毕。
  • 你编译和构建你的项目了吗??
  • 是的,错误依旧: 渲染问题 The following classes could not be found:android.support.v4.widget.Drawer Layout (Fix Build Path, Create Class) 提示:尝试构建项目。
  • 我添加了,但错误仍然存​​在。我有这个:依赖项 { compile fileTree(include: ['*.jar'], dir: 'libs') compile 'com.android.support:support-v4:22.1.1' compile 'com.android.support:appcompat -v7:22.1.1' 编译'com.android.support:recyclerview-v7:22.1.1' 编译'com.android.support:support-v13:22.1.1' }
  • 我是第一次加入堆栈,我只有在成功时才接受回复?
猜你喜欢
  • 1970-01-01
  • 2020-06-21
  • 1970-01-01
  • 2016-03-16
  • 1970-01-01
  • 1970-01-01
  • 2015-10-23
  • 1970-01-01
  • 2017-10-02
相关资源
最近更新 更多