Android的问题图库视图 [英] Android GalleryView Problem

查看:117
本文介绍了Android的问题图库视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Android的一图库视图问题,在我的应用我有很多照片。我想通过gallerview显示他们,让他们选择。我想通了,显示它们横向滚动,使他们有选择图库视图,但我需要在屏幕上一个图像的时间,水平滚动条滚动的用户后,另一张照片必须证明。我的测试code是下面这显示在屏幕上3张照片,从 HTTP:// WWW .androidpeople.com / Android的画廊 - 例如的:

I have a problem with android galleryview, in my app I have a lot of pictures. And I wanna display them by gallerview and make them selectable. I figured out displaying them horizontal scrollable and make them selectable with Galleryview, but I need one image on the screen at a time, after horizontal scrolling the scrollbar by the user, another picture must be shown. My test code is below and this shows 3 pictures on the screen, from http://www.androidpeople.com/android-gallery-example:

        package com.projects.cards;

    import android.app.Activity;
    import android.content.Context;
    import android.content.res.TypedArray;
    import android.os.Bundle;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.AdapterView;
    import android.widget.AdapterView.OnItemClickListener;
    import android.widget.BaseAdapter;
    import android.widget.Gallery;
    import android.widget.ImageView;
    import android.widget.Toast;

public class GaleryTestActivity extends Activity {

private Gallery gallery;

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

    gallery = (Gallery) findViewById(R.id.examplegallery);
    gallery.setAdapter(new AddImgAdp(this));

    gallery.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView parent, View v, int position, long id) {
            // Displaying the position when the gallery item in clicked
            Toast.makeText(GaleryTestActivity.this, "Position=" + position, Toast.LENGTH_SHORT).show();
        }
    });

}

public class AddImgAdp extends BaseAdapter {
    int GalItemBg;
    private Context cont;

    // Adding images.
    private Integer[] Imgid = {
            R.drawable.a_1, R.drawable.a_2, R.drawable.a_3, R.drawable.a_4, R.drawable.a_5, R.drawable.a_6, R.drawable.a_7
    };

    public AddImgAdp(Context c) {
        cont = c;
        TypedArray typArray = obtainStyledAttributes(R.styleable.GalleryTheme);
        GalItemBg = typArray.getResourceId(R.styleable.GalleryTheme_android_galleryItemBackground, 0);
        typArray.recycle();
    }

    public int getCount() {
        return Imgid.length;
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imgView = new ImageView(cont);

        imgView.setImageResource(Imgid[position]);
        // Fixing width & height for image to display
        imgView.setLayoutParams(new Gallery.LayoutParams(200, 160));
        imgView.setScaleType(ImageView.ScaleType.FIT_XY);
        imgView.setBackgroundResource(GalItemBg);

        return imgView;
    }
}

}

我该如何解决这个问题呢?

How can I solve this problem?

在此先感谢..

推荐答案

据我了解,你想在当前聚焦图像占用所有的屏幕空间。您可以通过设置在您绑定到库(在getView)的ImageView的宽度达到这个目标。尝试设置图像的宽度符合该设备屏幕的宽度。

As I understand it, you want the currently focused image to take up all the screen space. You can achieve this by setting the width of the ImageView where you bind it to the Gallery (in getView). Try setting the width of the image to match the width of the device screen.

请注意,您还可以设置的项目之间的间距与gallery.setSpacing(...)方法的画廊。

Note that you can also set the spacing between the items in the Gallery with the gallery.setSpacing(...) method.

我不能告诉你如何显示滚动条,很抱歉。

I can not tell you how to show a scrollbar, sorry.

这篇关于Android的问题图库视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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