android 代码添加图片,向Android Gallery添加说明 - (图片和文字)

public void onClick(View v, int scelta) {

// in base all'intero della scelta ho una voce del menu :)

if (scelta == 1) {

Intent i = new Intent(this, Parco.class);

startActivity(i);

} else if (scelta == 2) {

Intent j = new Intent(this, Servizi.class);

startActivity(j);

} else {

this.startActivity(new Intent(

Intent.ACTION_VIEW,

Uri.parse("http://maps.google.com/maps?f=d&saddr=37.4,-121.9&daddr=Bellevue, WA&hl=en")));

}

}

public class ImageAdapter extends BaseAdapter {

private Context ctx;

private int itemBackground;

public ImageAdapter(Context c) {

ctx = c;

// Style

TypedArray a = obtainStyledAttributes(R.styleable.Gallery01);

itemBackground = a.getResourceId(

R.styleable.Gallery01_android_galleryItemBackground, 0);

a.recycle();

}

@Override

public int getCount() {

return pics.length;

}

@Override

public Object getItem(int arg0) {

return arg0;

}

@Override

public long getItemId(int arg0) {

return arg0;

}

@Override

public View getView(int elemento, View arg1, ViewGroup arg2) {

LinearLayout layout = new LinearLayout(getApplicationContext());

layout.setOrientation(LinearLayout.VERTICAL);

ImageView img = null;

// Riutilizziamo l'eventuale convertView.

if (arg1 == null) {

img = new ImageView(ctx);

} else {

img = (ImageView) arg1;

}

img.setImageResource(pics[elemento]);

img.setScaleType(ImageView.ScaleType.FIT_XY);

img.setLayoutParams(new Gallery.LayoutParams(280, 210));

img.setBackgroundResource(itemBackground);

TextView tv = new TextView(ctx);

String titolo = "";

if (elemento == 0) {

titolo = "le Grotte";

} else if (elemento == 1) {

titolo = "il Parco";

} else if (elemento == 2) {

titolo = "i Servizi";

}

tv.setText(titolo);

tv.setGravity(Gravity.CENTER);

// Utilizzo l'AssetManager per cambiare il font

AssetManager assetManager = getResources().getAssets();

Typeface typeface = Typeface.createFromAsset(assetManager,

"fonts/CALIFR.TTF");

tv.setTypeface(typeface);

tv.setTextSize(50);

tv.setPadding(0, 0, 0, 40); // imposto il margine di bottom del

// testo

layout.addView(img);

layout.addView(tv);

return layout;

}

}

@Override

public View makeView() {

ImageView iView = new ImageView(this);

iView.setScaleType(ImageView.ScaleType.FIT_CENTER);

iView.setLayoutParams(new ImageSwitcher.LayoutParams(

LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

iView.setBackgroundColor(0xFF000000);

return iView;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值