Picture Viewer in Android

Source: Internet
Author: User

In this case, use Eclipse to develop a picture viewer for the Android2.1 version number.

1) First, open eclipse. Create a new project with a Android2.1 version number SHOWTU, open the Strings.xml in the Res/values folder, and replace the code with the following:

Path: Showtu/res/valus/string.xml

<?xml version= "1.0" encoding= "Utf-8"?

><resources> <string name= "Hello" >hello world, showtuactivity!</string> <string Name= "App_name" >showtu</string><string name= "pre" > previous </string><string name= "after" > Next pair of </string></resources>


2) Open the Main.xml under the Res/layout file with two button controls and a ImageView control in the layout file. The code in this example is as follows:

Path: Showtu/res/layout/main.xml

<?

XML version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android "Android:layout_width=" fill_parent "android:layout_height=" fill_parent "android:orientation=" vertical "><! --Horizontal line layout--><linearlayout android:id= "@+id/linearlayout01" android:orientation= "Horizontal" android:layout_ Width= "wrap_content" android:layout_gravity= "center" android:layout_height= "Wrap_content" > <!--Button Control-- ><button android:text= "@string/pre" android:id= "@+id/button01" android:textcolor= "#000000" Android:layout_ Width= "Wrap_content" android:layout_height= "wrap_content" ></button><button android:text= "@string/ After "android:id=" @+id/button02 "android:textcolor=" #000000 "android:layout_width=" Wrap_content "Android:layout_ height= "Wrap_content" ></button></linearlayout><imageview android:id= "@+id/ImageView01" Android : layout_width= "wrap_content" android:layout_height= "Wrap_content" Android:layout_gravity= "center" > </ImageView> <textview android:layout_width= "Fill_parent" android:layout_height= "Wrap_content" android:text= "@string/hello"/> </LinearLayout>


3) Next. The main activity file Showtuactivity.java, code such as the following:

Path: Src/com.tu.ui/showtuactivity.java

Package Com.tu.ui;import Android.app.activity;import Android.os.bundle;import android.view.view;import Android.view.view.onclicklistener;import Android.widget.button;import Android.widget.imageview;import Android.widget.toast;public class Showtuactivity extends activity {/** Called when the activity is first created. */im Ageview iv;//declaration ImageView Control int count;//counter int drawableids[]={//picture ID array R.drawable.pic0,r.drawable.pic1, R.drawable.pic2,r.drawable.pic3,r.drawable.pic4,r.drawable.pic5,r.drawable.pic6,r.drawable.pic7,    R.DRAWABLE.PIC8,R.DRAWABLE.PIC9};        @Override public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.main);//Set Layout iv= (ImageView) Findviewbyid (R.ID.IMAGEVIEW01);//Get ImageView references Iv.setima Geresource (R.DRAWABLE.PIC0);//Set image button pre_btn= (button) Findviewbyid (r.id.button01);//Get a reference to the previous Button Pre_b Tn.setonclicklistener (//Join Listener New Onclicklistener () {@Overridepublicvoid OnClick (View v) {if (count>0) {Iv.setimageresource (Drawableids[--count]);//Set Image}else{toast.maketext (        Showtuactivity.this, "This is the first picture", Toast.length_short). Show ();}}        }        ); Button after_btn= (button) Findviewbyid (R.ID.BUTTON02);//Gets the reference of the next Button after_btn.setonclicklistener (//Join listener N EW Onclicklistener () {@Overridepublic void OnClick (View v) {if (count<drawableids.length-1) {Iv.setimageresource (dr        Awableids[++count]);//Set Image}else{toast.maketext (Showtuactivity.this, "This is the last picture", Toast.length_short). Show ();}}    }        ); }}

Effects such as the following:

Figure (1)

Figure (2)

Picture Viewer in Android

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.