MainActivity 内需要定义一个int[]类型的数组
public class MainActivity extends AppCompatActivity {
private ImageBannerFrameLayout mGroup;
private int[] ids = new int[]{R.drawable.aa,R.drawable.bb,R.drawable.cc,R.drawable.dd};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mGroup = (ImageBannerFrameLayout) findViewById(R.id.imageGroup);
//需要计算出手机的宽度
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
Utils.width = dm.widthPixels;
List<Bitmap> list = new ArrayList<>();
for (int i = 0; i < ids.length; i++) {
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), ids[i]);
list.add(bitmap);
}
mGroup.addBitmaps(list);
}
}
在布局文件中写出布局
<com.example.administrator.autobanner.ImageBannerFrameLayout
android:id="@+id/imageGroup"
android:layout_width="match_parent"
android:layout_height="300px"/>