我不知道实施后如何使用smarteist / Android-Image-Slider。我用onCreate()
写,但是SliderView
无法解析符号
此实现链接https://github.com/smarteist/Android-Image-Slider
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SliderView sliderView = findViewById(R.id.imageSlider);
sliderView.setSliderAdapter(new SliderAdapterExample(this));
sliderView.setIndicatorAnimation(IndicatorAnimations.SWAP); //set indicator animation by using SliderLayout.IndicatorAnimations. :WORM or THIN_WORM or COLOR or DROP or FILL or NONE or SCALE or SCALE_DOWN or SLIDE and SWAP!!
sliderView.setSliderTransformAnimation(SliderAnimations.DEPTHTRANSFORMATION);
sliderView.setScrollTimeInSec(2); //set scroll delay in seconds :
sliderView.startAutoCycle();
答案 0 :(得分:0)
几个星期前,我遇到了这个库的问题。我建议将其转储并使用ViewHolder创建自己的滑块。 在我们使用https://developer.android.com/jetpack/docs/guide的示例中,您将需要图像加载库。 我们正在使用互联网加载图片并添加此权限
<uses-permission android:name="android.permission.INTERNET" />
请按照以下步骤操作:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.codinginflow.picassoimagesliderexample.MainActivity">
</android.support.v4.view.ViewPager>
ViewPageAdapter.java
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.squareup.picasso.Picasso;
public class ViewPagerAdapter extends PagerAdapter {
private Context context;
private String[] imageUrls;
ViewPagerAdapter(Context context, String[] imageUrls) {
this.context = context;
this.imageUrls = imageUrls;
}
@Override
public int getCount() {
return imageUrls.length;
}
@Override
public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
return view == object;
}
@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {
ImageView imageView = new ImageView(context);
Picasso.get()
.load(imageUrls[position])
.fit()
.centerCrop()
.into(imageView);
container.addView(imageView);
return imageView;
}
@Override
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
container.removeView((View) object);
}
}
MainActivity.java
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
private String[] imageUrls = new String[]{
"https://cdn.pixabay.com/photo/2016/11/11/23/34/cat-1817970_960_720.jpg",
"https://cdn.pixabay.com/photo/2017/12/21/12/26/glowworm-3031704_960_720.jpg",
"https://cdn.pixabay.com/photo/2017/12/24/09/09/road-3036620_960_720.jpg",
"https://cdn.pixabay.com/photo/2017/11/07/00/07/fantasy-2925250_960_720.jpg",
"https://cdn.pixabay.com/photo/2017/10/10/15/28/butterfly-2837589_960_720.jpg"
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ViewPager viewPager = findViewById(R.id.view_pager);
ViewPagerAdapter adapter = new ViewPagerAdapter(this, imageUrls);
viewPager.setAdapter(adapter);
}
}
这是我朋友https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/update.html的代码