0

私のアプリにはたくさんの写真があります。そして、gallerviewで表示して選択できるようにしたいです。それらを水平スクロール可能に表示し、Galleryviewで選択できるようにしましたが、一度に画面に1つの画像が必要です。ユーザーがスクロールバーを水平スクロールした後、別の画像を表示する必要があります。私のテストコードは以下にあり、これはhttp://www.androidpeople.com/android-gallery-exampleからの3つの写真を画面に表示します:

        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;
    }
}

}

どうすればこの問題を解決できますか?

前もって感謝します..

4

3 に答える 3

0

私が理解しているように、現在フォーカスされている画像がすべての画面スペースを占有する必要があります。これは、(getView で) ギャラリーにバインドする ImageView の幅を設定することで実現できます。デバイスの画面の幅に合わせて画像の幅を設定してみてください。

gallery.setSpacing(...) メソッドを使用して、ギャラリー内のアイテム間の間隔を設定することもできます。

スクロールバーの表示方法がわかりません、申し訳ありません。

于 2011-06-28T10:34:20.180 に答える
0

以下のリンクに記載されているようなギャラリービューを実装しました。こちらもお試しください:キャプション付き Android ギャラリー

于 2011-06-28T08:49:04.680 に答える