1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| public class MarkerView extends LinearLayout {
private TextView description; // La description s'affichant sur le marqueur
/**
* Constructeur créant la vue associée au marqueur passé en paramètre
*
* @param context
* @param marker
*/
public MarkerView(Context context, Marker marker) {
super(context);
this.marker = marker;
description.setText("Mon texte de 2 lignes");
description.setMaxLines(2);
description.setTextColor(Color.BLACK);
// Image
ImageView img = new ImageView(this.getContext());
img.setImageResource(R.drawable.image);
// Essais pour récupérer la taille du texte et modifier la taille max de l'image en conséquence, mais description.getHeight() renvoie toujours 0.
//addView(description);
//int h= description.getHeight(); // Renvoie 0
//System.out.println(h);
//this.removeAllViews();
//img.setMaxHeight(h);
// Background du Layout
setBackgroundResource(R.drawable.fond);
// On ajoute l'image
addView(img);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
params.gravity = Gravity.CENTER;
params.leftMargin = 5;
// On ajoute le texte
addView(description, params);
}
} |
Partager