详细地址
MainActivity
package com.example.lll;
import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import com.youth.banner.Banner;
import com.youth.banner.loader.ImageLoader;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
private Banner banner ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
banner = findViewById(R.id.bannn);
banner.setImageLoader(new ImageLoader() {
@Override
public void displayImage(Context context, Object path, ImageView imageView) {
//强转BannerBean -> path
//加载具体页面
imageView.setImageResource((int)path);
}
});
//给数据 BannerBean
List<Integer> datas = new ArrayList<>();//Bean
datas.add(R.mipmap.ic_launcher);
datas.add(R.mipmap.ic_launcher);
datas.add(R.mipmap.ic_launcher);
datas.add(R.mipmap.ic_launcher);
banner.setImages(datas);
banner.start();
}
}
Activity
<com.youth.banner.Banner
android:layout_width="match_parent"
android:layout_height="200dp"
android:id="@+id/bannn"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
//Module里的build.gradle
implementation ‘com.youth.banner:banner:1.4.10’