Aligner les éléments dans cardview
Je veux ma carte de ressembler à ce qui suit
J'ai gardé la mise en page comme ceci
<android.support.v7.widget.CardView
android:layout_gravity="center"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
card_view:cardCornerRadius="2dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Order# GAMH2103"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:gravity="start"
android:textSize="15dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Confirmed"
android:drawableRight="@drawable/check"
android:textColor="#00FF00"
android:gravity="end"
android:textSize="15dp"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray"
android:layout_marginTop="5dp"
/>
</LinearLayout>
En quelque sorte, je ne suis pas en mesure d'obtenir le "confirmé" TextView visible. Je peux voir le n ° d'ordre même si.
J'ai joué avec le gravity
et layout_gravity
mais de toute façon ne pouvait pas passer à travers.
S'il vous plaît aider.
Merci, Lakshman.
- Parce que vous définissez la largeur de la "commande# si" TextView
android:layout_width="match_parent"
, de sorte que le "confirmé" TextView peut pas visible. Changement deandroid:layout_width="wrap_content"
. Vous pouvez ajouterandroid:layout_weight="1"
si vous voulez le "confirmé" TextView toujours visible.
Vous devez vous connecter pour publier un commentaire.
Utiliser la mise en page suivante.Cela fonctionne pour vous.
Il est toujours préférable à l'utilisation Relative de la Mise en page au lieu de Linéaire de mise en page pour une meilleure vue de l'alignement .
Un simple relative disposition devrait faire l'affaire.
Noter la différence entre
gravity
etlayout_gravity
, si vous utilisezgravity
dans unTextView
, il revient à la position du texte à l'intérieur de la invisible boîte de qui est la frontière deTextView
, ainsi, par exemple,layout_gravity
sur l'autre main se rapporte à la position de la vue à l'intérieur de la mère.