所以我想在我的回收者视图中添加一个'DividerItemDecoration',但它一直在说Cannot resolve symbol 'DividerItemDecoration'
。我通过创建自己的DividerItemDecoration类解决了这个问题。现在我想在我的Recycler视图中添加一个SnapHelper,它给我同样的错误。我的成绩依赖是最新的。我尝试了无效缓存/重新启动,但它没有帮助。想法?
package osoble.bloodhero.Fragments;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.google.firebase.database.ChildEventListener;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.SnapHelper;
import osoble.bloodhero.Adapters.BloodBankAdapter;
import osoble.bloodhero.Models.BloodBank;
import osoble.bloodhero.R;
public class BloodBankAppointmentFragment extends Fragment {
private static final String TAG = BloodBankAppointmentFragment.class.getSimpleName();
private RecyclerView bloodbankRecyclerView;
private BloodBankAdapter mAdapter;
private DatabaseReference mDatabaseRef;
private DatabaseReference childRef;
private ProgressDialog progress;
public BloodBankAppointmentFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.blood_bank_appointment, container, false);
Log.i(TAG, "Was Opened");
getActivity().setTitle("Set Appointment");
bloodbankRecyclerView = view.findViewById(R.id.r_blood_bank_search);
bloodbankRecyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, true));
progress = new ProgressDialog(getContext());
progress.setMessage("Loading...");
progress.setCancelable(false);
progress.show();
// SnapHelper snapHelperStart = new GravitySnapHelper(Gravity.START);
mDatabaseRef = FirebaseDatabase.getInstance().getReference();
mDatabaseRef.keepSynced(true);
childRef = mDatabaseRef.child("Blood Bank");
childRef.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
progress.dismiss();
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
mAdapter = new BloodBankAdapter(BloodBank.class, R.layout.blood_bank_row,
BloodBankAdapter.BloodBankViewHolder.class, childRef, getContext());
bloodbankRecyclerView.setAdapter(mAdapter);
bloodbankRecyclerView.setHasFixedSize(true);
bloodbankRecyclerView.addItemDecoration(
new DividerItemDecoration(bloodbankRecyclerView.getContext(), 3)
);
return view;
}
}
摇篮:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "osoble.bloodhero"
minSdkVersion 21
multiDexEnabled true
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.github.rubensousa:gravitysnaphelper:1.3'
compile 'jp.wasabeef:blurry:2.1.1'
compile 'de.hdodenhof:circleimageview:2.2.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:support-v4:26.1.0'
compile 'com.android.support:design:26.1.0'
compile 'com.android.support:recyclerview-v7:26.1.0'
compile 'com.google.firebase:firebase-core:11.0.4'
compile 'com.google.firebase:firebase-auth:11.0.4'
compile 'com.google.android.gms:play-services-auth:11.0.4'
compile 'com.google.firebase:firebase-database:11.0.4'
compile 'com.google.firebase:firebase-messaging:11.0.4'
compile 'com.google.firebase:firebase-storage:11.0.4'
compile 'com.google.firebase:firebase-ads:11.0.4'
compile 'com.facebook.android:facebook-android-sdk:4.22.1'
compile 'com.firebaseui:firebase-ui:0.6.0'
compile 'com.firebaseui:firebase-ui-storage:0.6.0'
testCompile 'junit:junit:4.12'
compile 'com.android.support:support-v13:27.0.1'
compile 'com.android.support:appcompat-v7:27.0.1'
compile 'devs.mulham.horizontalcalendar:horizontalcalendar:1.2.0'
}
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'com.android.support') {
if (!requested.name.startsWith("multidex")) {
details.useVersion '24.1.0'
}
}
}
}
apply plugin: 'com.google.gms.google-services'
答案 0 :(得分:0)
对于RecyclerView,你可以使用这个SpacesItemDecoration而不是DividerItemDecoration
package com.tijoyoutubes.helper;
import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;
public class SpacesItemDecoration extends RecyclerView.ItemDecoration {
private int space;
public SpacesItemDecoration(int space) {
this.space = space;
}
@Override
public void getItemOffsets(Rect outRect, View view,
RecyclerView parent, RecyclerView.State state) {
outRect.left = space;
outRect.right = space;
outRect.bottom = space;
// Add top margin only for the first item to avoid double space between items
if (parent.getChildLayoutPosition(view) == 0) {
outRect.top = space;
} else {
outRect.top = 0;
}
}
}
并使用
int spacingInPixels = 2;// getResources().getDimensionPixelSize(R.dimen.spacing);
recyclerView
.addItemDecoration(new SpacesItemDecoration(spacingInPixels));
实施
答案 1 :(得分:0)
我必须从
进行更改android {
compileSdkVersion 24
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "sajilni.com.retrofit2httpclient"
minSdkVersion 15
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
为此(从最小SDK 15更改为25 )
android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "com.chikeandroid.retrofittutorial"
minSdkVersion 25
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
那么旧的SDK不支持它的原因,就是这么简单
还是我所做的,因为直到现在为止我都需要对IceCream 15 API的支持!
顺便说一句,我正在按照本教程实施 Get Started With Retrofit 2 HTTP Client