我正在努力使用新的android-studio并导入recyclerview。
我已经尝试了许多不同的方法来使Recyclerview工作:
activity_base.xml
<android.support.v4.widget.DrawerLayout
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:elevation="7dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:id="@+id/tool_bar"
layout="@layout/toolbar">
</include>
<TextView android:text="@string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<android.support.v7.RecyclerView
android:id="@+id/recycler_view"
android:scrollbars="vertical"
android:layout_width="320dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:background="@color/orange">
</android.support.v7.RecyclerView>
</android.support.v4.widget.DrawerLayout>
BaseActivity.java
package de.test.actionbarmd;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
public class BaseActivity extends AppCompatActivity {
private Toolbar mToolBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_base);
mToolBar = (Toolbar) findViewById(R.id.tool_bar);
setSupportActionBar(mToolBar);
}
}
的build.gradle
apply plugin: 'com.android.application'
repositories {
mavenCentral()
}
android {
compileSdkVersion 21
buildToolsVersion '21.1.2'
defaultConfig {
applicationId "de.test.actionbarmd"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.1.1'
//compile files('libs/recyclerview-v7-22.2.0.jar')
compile 'com.android.support:recyclerview-v7:22.2.0'
}
我总是得到以下例外:
java.lang.RuntimeException:无法启动活动 ComponentInfo {de.test.actionbarmd / de.test.actionbarmd.BaseActivity}: android.view.InflateException:二进制XML文件行#23:错误 膨胀类android.support.v7.RecyclerView
引起:android.view.InflateException:二进制XML文件行#23: 扩展类android.support.v7.RecyclerView
时出错引起:java.lang.ClassNotFoundException:没有找到类 路径上的“android.support.v7.RecyclerView”:DexPathList [[zip文件 “/data/app/de.test.actionbarmd-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /系统/ lib中]]
我做错了什么,或者是新的android -studio中的错误?
答案 0 :(得分:2)
它应该是$(function () {
$('#container').highcharts({
legend: {
align: 'left',
verticalAlign: 'top',
layout: 'horizontal'
},
navigation: {
buttonOptions: {
align: 'right',
verticalAlign: 'top'
}
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
title: {
text: null
},
yAxis: {
max: 1
},
series: [{
name: 'Type 1',
data: [0.6, 0.5, 0.2, 0.3, 0.8, 1, 0.6, 0.5, 0.4, 0.1, 0.6, 0.8]
}, {
name: 'Type 2',
data: [0.2, 0.8, 0.7, 0.3, 0.4, 0.7, 0.8, 0.9, 1, 0.3, 0.2, 0.5]
}],
});
});
,你在布局中缺少单词android.support.v7.widget.RecyclerView
,因此找不到类,
正确的代码:
widget