Android的形象和QUOT;观众QUOT;应用程序 [英] android image "viewer" app

查看:115
本文介绍了Android的形象和QUOT;观众QUOT;应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个Android应用程序,可以让我显示图像全屏下一个和previous按钮,在顶部它们之间切换。

I am trying to create an android app that will let me display images fullscreen with next and previous buttons on top to change between them.

任何人都可以点我的一些教程在那里我可以找到类似的说明?

Can anybody point me to some tutorials where i can find instructions on something similar?

如果没有,什么是用于获取图像到应用程序的最佳方法是什么?我曾尝试多种方法,从该图像创建对象类,并使用位图厂返回图像与绘制实例化在每个但这是行不通的。

If not, what is the best method to use to get the images into the app? I have tried several ways from creating object classes for the images and instantiating it with a drawable in each using the Bitmap Factory to return the image but that won't work.

我是一个初学者到Android和真的可以使用的参考材料,但无法找到覆盖这个主题有用的东西。

I am a beginner to android and could really use reference material but can't find anything useful that covers this subject.

推荐答案

作为一个新手,我自己,我一直使用这个,这是非常简单的。下面是一些code(也许有更好的方法,但是这是我想通了,如何做到这一点的方式):

As a newbie myself I've been working with this and it's very simple. Here is some code (maybe there is a better way but this is the way I figured out how to do it):

package com.imageviewexample;

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;

public class ImageViewExample extends Activity implements OnClickListener {

    /** Called when the activity is first created. */

    int image_index = 0;
    private static final int MAX_IMAGE_COUNT = 3;

    private Integer[] mImageIds = {
            R.raw.image1,
            R.raw.image2,
            R.raw.image3
    };

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Button btnPrevious = (Button)findViewById(R.id.previous_btn);
        btnPrevious.setOnClickListener(this);       
        Button btnNext = (Button)findViewById(R.id.next_btn);
        btnNext.setOnClickListener(this);

        showImage();        

    }

    private void showImage() {

        ImageView imgView = (ImageView) findViewById(R.id.myimage);             
        imgView.setImageResource(mImageIds[image_index]);       

    }

    public void onClick(View v) {

        switch (v.getId()) {

            case (R.id.previous_btn):

                image_index--;

                if (image_index == -1) {                    
                    image_index = MAX_IMAGE_COUNT - 1;                  
                }

                showImage();

            break;

            case (R.id.next_btn):

                image_index++;

                if (image_index == MAX_IMAGE_COUNT) {               
                image_index = 0;                
            }

                showImage();

            break;      

        }

    }
}

这是的main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

<Button
    android:id="@+id/previous_btn"
    android:layout_width="124dip" 
    android:layout_height="wrap_content" 
    android:text="Previous"
    />

<Button
    android:id="@+id/next_btn"
    android:layout_width="124dip" 
    android:layout_height="wrap_content"
    android:layout_toRightOf="@+id/previous_btn" 
    android:text="Next"
    />

<ImageView
    android:id="@+id/myimage"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:layout_below="@+id/previous_btn"
    />         

</RelativeLayout>

这篇关于Android的形象和QUOT;观众QUOT;应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆