在我的应用程序中,我有一个galleryview。所有的图片都是捶打,我想在选择时以某种动作视图打开图片。
但我似乎无法找到如何。任何人都可以帮忙吗?
编辑: 我的图库未从SD卡加载。它是使用应用程序内部资源目录中的图片生成的。
我的代码:
import dk.appsfabrikken.iphonetabs.R;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.AdapterView.OnItemClickListener;
public class CombarActivity extends Activity {
private Gallery gallery;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.combar);
//Knapper instantieres
Button butMarked = (Button)findViewById(R.id.btmarket);
//Opretter on click listerner til enkelt klik
butMarked.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
onclick_btmarket();
}
});
//Gallery findes på layout
gallery = (Gallery) findViewById(R.id.gallery1);
gallery.setAdapter(new AddImgAdp(this));
//Onlick listerner oprettes
gallery.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
}
});
}
public class AddImgAdp extends BaseAdapter {
int GalItemBg;
private Context cont;
// Tilføjer billeder til gallery
private Integer[] Imgid = {
R.drawable.combar2, R.drawable.combar1};
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]);
// Tilpasser højde og bredde for billeder i gallery. Tester skærmstørrelse og tilpasser.
if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_SMALL) {
imgView.setLayoutParams(new Gallery.LayoutParams(110, 170));
}
else{
imgView.setLayoutParams(new Gallery.LayoutParams(220, 340));
}
imgView.setScaleType(ImageView.ScaleType.FIT_XY);
imgView.setBackgroundResource(GalItemBg);
return imgView;
}
}
//Udfører opgave for click på knap
private void onclick_btmarket() {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://market.android.com/details?id=dk4.ef.cms"));
startActivity(browserIntent);}
;
}
提前完成。