1

このレイアウトを使用すると「btnAdd」というボタンが表示されない理由がわかりません。私はLinearLayoutと現在のRelativeLayoutの両方を試しましたが、両方で目に見えません。Android:ボタンがレイアウトに表示されない

<?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> 

答えて

1

私は今、携帯電話ので、私はこれをテストすることはできませんが、私はあなたがやっていると思う間違っ以下:

あなたがtxtNameの幅としてfill_parentを使用しているため、とtxtName btnAddの前に追加されていますが、btnAddの幅は残っていません。私は、2つの要素を追加する順番を切り替えるだけで十分だと思います(これを行う際にlayout_toRightOf/LeftOfの調整が必要な場合もあります)。

更新:
私がチェックされ、私が言ったように、それは正しかった:テキストフィールドを追加する際に

  • がテキストフィールド
  • 使用layout_toLeftOf前にボタンを追加します。

最終的な結果は次のようになります。

あなたAutoCompleteTextViewは、画面全体を占有している、fill_parentを持っているためだ
<?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

ありがとう、完璧に働いています。 – Echilon

0

、例えばAutoCompleteTextViewのlayout_width = "100dip"を指定すると、ボタンが表示されます。 layout_weightsを使用してボタンとビューのスペースを確保することをお勧めします。

関連する問題