I'm working on my new project but I can't figure out how to add a text under my Gallery.
I have 3 pictures, if I slide on picture 2 I can see under picture 1 and 3 the correct description but it doesn't appear the description under the selected picture (in this case the number 2).
This is my code:
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(开发者_StackOverflow0, 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;
}
Thank you!!! Marco
Use: tv.setTextColor(0xffffffff);
The TextView class has attributes to place a Drawable above, below, etc
精彩评论