1

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

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

2 に答える 2

1

私は今携帯電話を使用しているので、これをテストすることはできませんが、あなたは次のことを間違っていると思います。

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

更新:
私はチェックしました、そして私が言ったようにそれは正しかったです:

  • テキストフィールドの前にボタンを追加します
  • テキストフィールドを追加するときは、layout_toLeftOfを使用します。

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

<?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>
于 2011-01-01T14:55:50.913 に答える
0

これは、AutoCompleteTextViewにfill_parentがあり、これが画面全体を占めているためです。たとえば、AutoCompleteTextViewにlayout_width = "100dip"を指定すると、ボタンが表示されます。ボタンとビューにスペースを与えるためにlayout_weightsを使用することをお勧めします。

于 2011-01-01T14:56:28.957 に答える