J'ai besoin de mettre une vue de texte au milieu d'une vue imageView, donc j'ai ce code p> et j'ai besoin du dernier TextView pour toujours être au centre du menu_icon imageview mais mon méthadot ne fonctionne pas, cela ne le met pas dans le coin supérieur gauche. P> P>
3 Réponses :
Vous devez juste avoir besoin d'ajouter: à votre dernier textview p> p> p>
Comme votre imageView ne remplit pas tout relativelayout, vous ne pouvez pas atteindre un effet souhaitable. Je vous suggère de placer imageView et TextView à Framelayout.
<FrameLayout android:layout_width = "wrap_content" android:layout_height = "wrap_content" android:layout_alignParentRight="true" android:layout_centerInParent="true"> <TextView android:id="@+id/menu_label" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:lines="1" /> <ImageView android:id="@+id/menu_icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginBottom="@dimen/menu_icon_margin_top_bottom" android:layout_marginRight="@dimen/menu_icon_margin_right" android:layout_marginTop="@dimen/menu_icon_margin_top_bottom" /> </FrameLayout>
Merci, c'était très utile. J'ai toujours tendance à oublier Framelayout.
framelayout code> est le meilleur moyen d'aller. Vous pouvez utiliser un
relativenelayout code> aussi, BTW.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="40dp"
android:layout_height="40dp">
<ImageView
android:id="@+id/marker_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
tools:src="@drawable/ic_marker_selected" />
<TextView
android:id="@+id/marker_title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:textColor="#fff"
android:textSize="14sp"
tools:text="A" />
</FrameLayout>
Add
Android: Gravity = "Centre" code> à votre TextView.