我與Android一圖庫視圖問題,在我的應用我有很多的圖片。我想通過gallerview顯示它們並使它們可選。我想通過水平滾動顯示它們,並使用Galleryview選擇它們,但是我一次需要在屏幕上顯示一個圖像,在用戶水平滾動滾動條之後,必須顯示另一張圖像。我的測試代碼如下,這顯示在屏幕上3張圖片,從http://www.androidpeople.com/android-gallery-example:Android的問題圖庫視圖
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;
}
}
}
我怎樣才能解決這個問題?
在此先感謝..
我需要的只是間隔! gallery.setSpacing(100);然後我在屏幕上看到一個圖像。此外,我不需要一個可見的滾動條,如果觸摸事件發生,Android操作系統處理滾動我,特別感謝... – barisatbas