7
votes

Insertion d'un TextView au milieu d'un Android de l'image de l'image

J'ai besoin de mettre une vue de texte au milieu d'une vue imageView, donc j'ai ce code xxx

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.


1 commentaires

Add Android: Gravity = "Centre" à votre TextView.


3 Réponses :


3
votes

Vous devez juste avoir besoin d'ajouter: xxx

à votre dernier textview


0 commentaires

19
votes

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>


1 commentaires

Merci, c'était très utile. J'ai toujours tendance à oublier Framelayout.



1
votes

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>


0 commentaires