1

Je suis étonné de savoir pourquoi le bouton "btnAdd" n'apparaît pas lorsque j'utilise cette disposition. J'ai essayé à la fois un LinearLayout et le RelativeLayout actuel, mais il est invisible dans les deux.Android: Le bouton n'apparaît pas dans la présentation

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:padding="5dp"> 
    <RelativeLayout 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 
     <TextView 
     android:id="@+id/lblName" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="5dp" 
     android:text="@string/category" /> 
     <AutoCompleteTextView 
     android:id="@+id/txtName" 
     android:layout_marginRight="5dp" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/lblName" 
     android:textColor="#000000" 
     android:singleLine="true"/> 
     <Button 
     android:id="@+id/btnAdd" 
     android:layout_width="100dip" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_toRightOf="@id/txtName" 
     android:text="@string/add"/> 
    </RelativeLayout> 
    <TextView 
     android:id="@+id/android:empty" 
     android:layout_marginTop="4dp" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/current_categories" 
     /> 
    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_marginTop="2dp"> 
    <ListView 
     android:id="@+id/android:list" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"/> 
    <TextView 
     android:id="@+id/android:empty" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/recipe_uncategorized" 
     /> 
    </LinearLayout> 
</LinearLayout> 

Répondre

1

Je suis sur un téléphone mobile maintenant, donc je ne peux pas tester, mais je pense que vous faites le mauvais suivant:

Puisque vous utilisez fill_parent comme largeur sur txtName et txtName est ajouté avant btnAdd, il n'y a plus de largeur pour btnAdd. Je pense qu'il devrait être suffisant de changer l'ordre dans lequel vous ajoutez les deux éléments (vous devrez peut-être aussi faire un ajustement de la layout_toRightOf/LeftOf lorsque vous faites cela).

Mise à jour:
j'ai vérifié, et il était correct comme je l'ai dit:

  • Ajouter le bouton avant que le champ texte
  • Utilisation layout_toLeftOf lors de l'ajout du champ de texte.

résultat final devrait ressembler à ceci:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:padding="5dp"> 
    <RelativeLayout 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 
     <TextView 
     android:id="@+id/lblName" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="5dp" 
     android:text="@string/category" /> 
     <Button 
     android:id="@+id/btnAdd" 
     android:layout_width="100dip" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/lblName" 
     android:layout_alignParentRight="true" 
     android:text="@string/add"/> 
     <AutoCompleteTextView 
     android:id="@+id/txtName" 
     android:layout_marginRight="5dp" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/lblName" 
     android:layout_toLeftOf="@id/btnAdd" 
     android:textColor="#000000" 
     android:singleLine="true"/> 
    </RelativeLayout> 
    <TextView 
     android:id="@+id/android:empty" 
     android:layout_marginTop="4dp" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/current_categories" 
     /> 
    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_marginTop="2dp"> 
    <ListView 
     android:id="@+id/android:list" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"/> 
    <TextView 
     android:id="@+id/android:empty" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/recipe_uncategorized" 
     /> 
    </LinearLayout> 
</LinearLayout> 
+0

Merci, a parfaitement fonctionné. – Echilon

0

C'est parce que votre AutoCompleteTextView a fill_parent, qui occupe tout l'écran, par exemple donne layout_width = "100dip" pour AutoCompleteTextView et votre bouton apparaîtra. Je vais vous suggérer d'utiliser layout_weights pour donner de la place à vos boutons et vos vues.

Questions connexes