Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/184.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 具有回收视图和卡片视图的物料导航抽屉_Android_Android Studio_Material Design - Fatal编程技术网

Android 具有回收视图和卡片视图的物料导航抽屉

Android 具有回收视图和卡片视图的物料导航抽屉,android,android-studio,material-design,Android,Android Studio,Material Design,我正在尝试使用(android4devs)中的以下材料导航抽屉: 因此,以下是我的主要活动: <?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/DrawerLayout" android:lay

我正在尝试使用(android4devs)中的以下材料导航抽屉:

因此,以下是我的主要活动:

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

<android.support.v4.widget.DrawerLayout

    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/DrawerLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:elevation="7dp">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">


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

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello World" />

    </LinearLayout>


    <android.support.v7.widget.RecyclerView
        android:id="@+id/RecyclerView"
        android:layout_width="320dp"
        android:layout_height="match_parent"
        android:layout_gravity="left"

        android:background="#ffffff"
        android:scrollbars="vertical">

    </android.support.v7.widget.RecyclerView>


</android.support.v4.widget.DrawerLayout>
结果后的图片(添加卡片视图):

http://i.stack.imgur.com/1tRXy.png
http://i.stack.imgur.com/mAHtn.png
我的android studio预览版有一个问题,所以我无法准确地看到它,但当我需要看到结果时,我必须在emulator上运行它

关于预览和错误的问题:

关于这项主要活动:

The following classes could not be found:
- android.support.v4.widget.DrawerLayout (Fix Build Path, Create Class)
- android.support.v7.widget.CardView (Fix Build Path, Create Class)
 Tip: Try to build the project.
Build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.0"

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

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.1.1'
compile 'com.android.support:recyclerview-v7:22.0.0'
compile 'com.android.support:cardview-v7:22.0.0'
compile 'de.hdodenhof:circleimageview:1.2.1'
}
顺便说一下

如何在MainActivity上添加此卡片视图


干杯

尝试将布局文件更改为此,看看是否注意到任何差异

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/DrawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="7dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <include
            android:id="@+id/tool_bar"
            layout="@layout/tool_bar">
        </include>

        <android.support.v7.widget.CardView
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         card_view:contentPadding="16dp"
         card_view:cardElevation="2dp"
         card_view:cardCornerRadius="5dp">

        <TextView
            style="@style/Base.TextAppearance.AppCompat.Headline"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Title" />

        <TextView
            style="@style/Base.TextAppearance.AppCompat.Body1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Content here" />
    </android.support.v7.widget.CardView>
    </LinearLayout>


<android.support.v7.widget.RecyclerView
    android:id="@+id/RecyclerView"
    android:layout_width="320dp"
    android:layout_height="match_parent"
    android:layout_gravity="left"
    android:background="#ffffff"
    android:scrollbars="vertical">
</android.support.v7.widget.RecyclerView>

</android.support.v4.widget.DrawerLayout>


您是否实际运行了该应用程序?你那样做的时候有没有出错?不要担心预览。Android Studio尚未正确配置,无法在预览窗口中显示RecyclerView和CardView等内容。您的CardView显示得很好。您可以看到CardView内部的文本(即此处的标题和内容)显示正确。我不明白你的问题是什么?主代码:
http://i.stack.imgur.com/1tRXy.png
导航抽屉没有问题。-第二个代码(带cardview):
http://i.stack.imgur.com/mAHtn.png
现在,最好做出决定!您的导航抽屉布局在哪里?你从左边拉的那个?是的。正如你在本教程中所看到的:
www.android4devs.com/2014/12/如何制作材质设计导航drawer.html
我刚刚编辑了显示抽屉布局末端的代码。谢谢:)
apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.0"

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

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.1.1'
compile 'com.android.support:recyclerview-v7:22.0.0'
compile 'com.android.support:cardview-v7:22.0.0'
compile 'de.hdodenhof:circleimageview:1.2.1'
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/DrawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="7dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <include
            android:id="@+id/tool_bar"
            layout="@layout/tool_bar">
        </include>

        <android.support.v7.widget.CardView
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         card_view:contentPadding="16dp"
         card_view:cardElevation="2dp"
         card_view:cardCornerRadius="5dp">

        <TextView
            style="@style/Base.TextAppearance.AppCompat.Headline"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Title" />

        <TextView
            style="@style/Base.TextAppearance.AppCompat.Body1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Content here" />
    </android.support.v7.widget.CardView>
    </LinearLayout>


<android.support.v7.widget.RecyclerView
    android:id="@+id/RecyclerView"
    android:layout_width="320dp"
    android:layout_height="match_parent"
    android:layout_gravity="left"
    android:background="#ffffff"
    android:scrollbars="vertical">
</android.support.v7.widget.RecyclerView>

</android.support.v4.widget.DrawerLayout>