【发布时间】:2014-08-27 16:29:32
【问题描述】:
我在一个 android 项目上,我需要导入 ActionBar-PullToRefresh 库,所以我使用 gradle 导入该库,如下所示:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile('com.android.support:appcompat-v7:20.0.0') {
force = true
}
compile('com.android.support:support-v4:20.0.0') {
force = true
}
repositories {
mavenCentral()
}
compile 'com.github.chrisbanes.actionbarpulltorefresh:extra-abc:+'
}
然后我Sync Project with Gradle Files,所以我可以在我的布局xml文件中使用PullToRefreshLayout。但是当我在我的片段代码中使用库的类时,我无法得到任何代码触发器。当我拼写整个类名PullToRefreshLayout 时,Android Studio 不会自动导入该类。那么问题来了。
接下来的两个文件是我根目录下的build.gradle文件和我的app目录:
根目录下的build.gradle文件
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
app目录下的build.gradle文件
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.ifeve.ifeveforandroid"
minSdkVersion 10
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile('com.android.support:appcompat-v7:20.0.0') {
force = true
}
compile('com.android.support:support-v4:20.0.0') {
force = true
}
repositories {
mavenCentral()
}
compile 'com.github.chrisbanes.actionbarpulltorefresh:extra-abc:+'
}
【问题讨论】:
-
@MartinCR 是的,但是 SwipeRefreshLayout 不支持在 ActionBar 上添加提示“拉动刷新”——这也是我使用这个库的原因。
-
G+ 也是 ChrisBanes pull2refresh 风格。我也不喜欢 SwipeRefreshLayout 触摸“反弹”效果。
-
@MartinCR 是的,我尝试了 SwipeRefreshLayout 但无法获得理想的效果。
标签: android android-studio pull-to-refresh android-actionbar-compat