Android Image Converter Sample _android

Source: Internet
Author: User
Tags image converter

Mainactivity.java

Copy Code code as follows:

Package Com.zhang.showPhoto;

Import Android.app.ActionBar.LayoutParams;
Import android.app.Activity;
Import Android.os.Bundle;
Import Android.view.View;
Import Android.view.View.OnClickListener;
Import Android.view.animation.AnimationUtils;
Import Android.widget.Button;
Import Android.widget.ImageSwitcher;
Import Android.widget.ImageView;
Import Android.widget.ViewSwitcher.ViewFactory;

public class Mainactivity extends activity {

Private int[] Imagid=new int[]{
R.DRAWABLE.IMG01,R.DRAWABLE.IMG02,R.DRAWABLE.IMG03,R.DRAWABLE.IMG04,
R.DRAWABLE.IMG05,R.DRAWABLE.IMG06,R.DRAWABLE.IMG07,R.DRAWABLE.IMG08,
R.drawable.img09,r.drawable.img10
};
private int index=0;
Private Imageswitcher Imageswitcher;
Private Button Up,down;

@Override
protected void OnCreate (Bundle savedinstancestate) {

Super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);

up= (Button) Findviewbyid (R.ID.BT1);
Down= (Button) Findviewbyid (R.ID.BT2);


Imageswitcher= (Imageswitcher) Findviewbyid (R.ID.IMAGSW1);
Imageswitcher.setinanimation (This, Android. Animationutils.loadanimation. r.anim.fade_in));
Imageswitcher.setoutanimation (This, Android. Animationutils.loadanimation. R.anim.fade_out));
Imageswitcher.setfactory (New Viewfactory () {


Public View Makeview () {
ImageView ImageView = new ImageView (mainactivity.this);
Imageview.setscaletype (ImageView.ScaleType.FIT_CENTER);
Imageview.setlayoutparams (New Imageswitcher.layoutparams (
Layoutparams.wrap_content,layoutparams.wrap_content
));
return ImageView;
}
});

Imageswitcher.setimageresource (Imagid[index]);

Up.setonclicklistener (New Onclicklistener () {

@Override
public void OnClick (View v) {
if (index>0) {
index--;
}else{
Index=imagid.length-1;
}
Imageswitcher.setimageresource (Imagid[index]);
}
});

Down.setonclicklistener (New Onclicklistener () {

@Override
public void OnClick (View v) {
if (index<imagid.length-1) {
index++;
}else{
index=0;
}
Imageswitcher.setimageresource (Imagid[index]);
}
});
}
}

Main.xml

Copy Code code as follows:

<?xml version= "1.0" encoding= "Utf-8"?>
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
android:background= "@drawable/bg1"
Android:id= "@+id/llayout"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent"
android:gravity= "Center"
android:orientation= "Horizontal" >

<button
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:text= "The Last One"
Android:id= "@+id/bt1"
/>
<imageswitcher
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:id= "@+id/imagsw1"
android:layout_gravity= "Center"
/>
<button
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:text= "The next One"
Android:id= "@+id/bt2"
/>

</LinearLayout>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.