Placer une image et d'un Texte voir dans la même ligne
J'ai plusieurs logos et je veux mettre un Textview juste à côté, de sorte qu'ils sont dans la même ligne. Je ne peux pas les placer dans la même ligne.s'il vous plaît aider moi. Je veux que mon textview juste à côté de mon image.
ma mise en page
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<!--
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
-->
<TextView
android:id="@+id/filmhall_contactdetails"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cinema_filmhall_contactdet"
android:textColor="#000000"
android:layout_margin="4dp"
android:toRightof="@+id/pointer"
android:textStyle="bold" />
<TextView
android:id="@+id/filmhall_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="32dp"
android:layout_marginTop="2dp"
android:text="@string/cinema_filmhall_address"
android:textColor="#000000"
android:textSize="12sp"
android:textStyle="bold" />
<ImageView
android:id="@+id/pointer"
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_marginLeft="4dp"
android:src="@drawable/pointer" />
<TextView
android:id="@+id/filmhall_telephone1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cinema_filmhall_tp1"
android:textColor="#000000"
android:layout_marginTop="2dp"
android:layout_marginLeft="32dp"
android:textSize="12sp"
android:textStyle="bold" />
<ImageView
android:id="@+id/telephone"
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_marginLeft="4dp"
android:src="@drawable/call" />
<TextView
android:id="@+id/filmhall_telephone2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cinema_filmhall_tp2"
android:textColor="#000000"
android:layout_marginTop="2dp"
android:layout_marginLeft="32dp"
android:textSize="12sp"
android:textStyle="bold" />
<ImageView
android:id="@+id/fax"
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_marginLeft="4dp"
android:src="@drawable/fax" />
<TextView
android:id="@+id/filmhall_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cinema_filmhall_email"
android:textColor="#000000"
android:layout_marginTop="2dp"
android:layout_marginLeft="32dp"
android:textSize="12sp"
android:textStyle="bold" />
<ImageView
android:id="@+id/message"
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_marginLeft="4dp"
android:src="@drawable/message" />
<TextView
android:id="@+id/filmhall_facility"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_marginTop="10dp"
android:text="@string/cinema_filmhall_facility"
android:textColor="#000000"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
android:id="@+id/fac1"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginLeft="4dp"
android:src="@drawable/fac1" />
<ImageView
android:id="@+id/fac3"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginLeft="4dp"
android:src="@drawable/fac3" />
<ImageView
android:id="@+id/fac2"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginLeft="4dp"
android:src="@drawable/fac2" />
</LinearLayout>
</LinearLayout>
- modifier android:orientation="horizontal"
- Les mettre dans leur propre imbriquée LinearLayouts tout comme le ImageViews au fond. Aussi, vous voudrez probablement les hauteurs de ces mises en page
wrap_content
. - dois-je utiliser linéaires distinctes mises en page ou puis-je utiliser un seul?
Vous devez vous connecter pour publier un commentaire.
Méthode 1:
Comme d'autres l'ont suggéré, vous pouvez avoir un imbriquée
LinearLayout
avec une orientation horizontale. Il contient les deuxTextView
etImageView
avec des poids définir en fonction de votre besoin.Voir Comment définir ImageView et le textView dans une seule ligne à l'intérieur d'un LinearLayout
Par exemple:
Méthode 2 [ Facile ]:
Puisque vous avez mentionné que vous avez plusieurs logos et que vous voulez définir le drawable/ImageView juste à côté, il y a un autre moyen plus facile. En supposant que vous voulez quelque chose comme ceci:
Vous pouvez utiliser android:drawableLeft ou similaires dans le
TextView
. Vous pouvez également définir la marge entre le drawable et le texte de la TextView à l'aide de android:drawablePadding. À l'aide de cette façon, vous n'avez pas besoin de l'appoint ImageView. Mais il dépend à la fin ce que vous cherchez.Voir Définir par programmation à gauche drawable dans un TextView
Espère que cette aide.
Vous pouvez utiliser TableRow ainsi. Ici, vous n'avez pas besoin de spécifier le android:orientation="horizontal".
Vous pouvez simplement utiliser
android:layout_centerVertical="true"
pour tous les points de vue Relatif de la Mise en page pour les faire en une seule ligne verticale.