如何在ViewFlipper中添加多个位图

问题描述 投票:2回答:1

[请帮助,我在数据库中检索了多个图像路径。该图像在Bitmap中转换。我在ViewFlipper中添加了此图像,使其看起来像幻灯片,但下一个图像没有出现。你能告诉我我做错了吗?这是我的代码:

ViewFlipper flip;

DatabaseHandler db;
List<GettersSetters> dbList;

int index =0;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_flip);

    Intent goFlip = getIntent();
    Bundle bundle = goFlip.getExtras();
    String getLocation = bundle.getString("path");

    db = new DatabaseHandler(this);
    dbList = new ArrayList<GettersSetters>();
    dbList = db.searchFromDB(getLocation);

    flip = (ViewFlipper) findViewById(R.id.flipper);

    flip.setInAnimation(this, R.anim.right_enter);
    flip.setOutAnimation(this, R.anim.left_out);

    String locate = "";

    if(dbList.size() > 0 ){

        for(GettersSetters currentClass : dbList){
            ImageView images = new ImageView(getApplicationContext());

            //This gets the image path in the database based on the index of recyclerview
            locate +=dbList.get(index++).getPath();

            //This converts the image path into Bitmap
            Bitmap img = decodeBitmapWithSize(locate,300,300,true);

            images.setImageBitmap(img);
            flip.addView(images);
            flip.setFlipInterval(3000);
            flip.startFlipping();
        }
    }
android database bitmap slideshow viewflipper
1个回答
0
投票

尝试下面的代码,而不是您在for循环中编写的代码:

Drawable drawable = new BitmapDrawable(getResources(), img);
images.setBackground(drawable);

它正在为我工​​作。

© www.soinside.com 2019 - 2024. All rights reserved.