android viewflipper 动态加载,如何在android中将动态图像设置为ViewFlipper?

我正在做这些正在加载静态这些图像?

public class ArchiveGroup extends Activity {

Button btn;

ViewFlipper flip;

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.next);

btn=(Button)findViewById(R.id.btn);

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

}

public void ClickHandler(View v)

{

flip.showNext();

}

public void ClickHandler1(View v)

{

Toast.makeText(this,"text",Toast.LENGTH_LONG).show();

}

}

我在xml文件中的ViewFlipper中使用了三个imageview

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/hello"

/>

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Flip"

android:id="@+id/btn"

android:onClick="ClickHandler"

/>

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:id="@+id/flip"

>

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:src="@drawable/ic_launcher"

/>

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:src="@drawable/ic_launcher"

/>

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:src="@drawable/ic_launcher"

/>

如何将动态图像设置为这些imageView.通过使用单个ImageView.

解决方法:

在你的xml中只添加这个,

android:layout_width="fill_parent"

android:layout_height="wrap_content">

不需要包含任何ImageViews.

现在在编码中执行此操作.

考虑到您已将图像存储在这样的数组中,

int gallery_grid_Images[]={R.drawable.gallery_image_1,R.drawable.gallery_image_2,R.drawable.gallery_image_3,

R.drawable.gallery_image_4,R.drawable.gallery_image_5,R.drawable.gallery_image_6,R.drawable.gallery_image_7,

R.drawable.gallery_image_8,R.drawable.gallery_image_9,R.drawable.gallery_image_10

};

现在在你的onCreate()中,

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

for(int i=0;i

{

// This will create dynamic image view and add them to ViewFlipper

setFlipperImage(gallery_grid_Images[i]);

}

现在将此方法添加到您的活动中,

private void setFlipperImage(int res) {

Log.i("Set Filpper Called", res+"");

ImageView image = new ImageView(getApplicationContext());

image.setBackgroundResource(res);

viewFlipper.addView(image);

}

而已.现在使用你的viewFlipper.showNext();和viewFlipper.showPrevious();

您可以显示动态图像的方法.

标签:viewflipper,android

来源: https://codeday.me/bug/20190923/1815429.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值