1

textView、editText、および listView があります。textView と editText を並べて注文したいので、 LinearLayout. さらに、それらの下に listView を作成します。これが XML です。

残念ながら、listView は表示されません。使用している ArrayList が空でないことを確認しました。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   tools:context=".MainActivity" 
   android:gravity="center"
   android:background ="#268496" >

<LinearLayout android:id="@+id/linear"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="match_parent">

 <TextView
    android:id="@+id/prefixText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#FFFFFF"
    android:textIsSelectable="true"
    android:textSize="12pt"
    android:typeface="sans" />

 <EditText
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:id="@+id/input"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:inputType="text"
    android:textSize="12pt"
    android:maxLength="1"
    android:typeface="sans" />

</LinearLayout>

<ListView
    android:id="@+id/listView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_below="@id/linear"
    android:layout_marginBottom="10dp"
    android:layout_marginTop="5dp"
    android:divider="#CCCCCC"
    android:dividerHeight="1dp"
    android:paddingLeft="2dp" >

   </ListView>

</RelativeLayout>

リストの作成:

public void listView (){
     ListView lv;
     setContentView(R.layout.activity_main);
     lv = (ListView) findViewById(R.id.listView);
     ArrayList<String> your_array_list = new ArrayList<String>();
     your_array_list.add("foo");
     your_array_list.add("bar");
     ArrayAdapter<String> arrayAdapter =      
     new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, your_array_list);
     lv.setAdapter(arrayAdapter); 

}
4

3 に答える 3

4

Linear Layout の高さは match_parent です。これを wrap_content に変更します

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   tools:context=".MainActivity" 
   android:gravity="center"
   android:background ="#268496" >

<LinearLayout android:id="@+id/linear"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

 <TextView
    android:id="@+id/prefixText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#FFFFFF"
    android:textIsSelectable="true"
    android:textSize="12pt"
    android:typeface="sans" />

 <EditText
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:id="@+id/input"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:inputType="text"
    android:textSize="12pt"
    android:maxLength="1"
    android:typeface="sans" />

</LinearLayout>

<ListView
    android:id="@+id/listView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_below="@id/linear"
    android:layout_marginBottom="10dp"
    android:layout_marginTop="5dp"
    android:divider="#CCCCCC"
    android:dividerHeight="1dp"
    android:paddingLeft="2dp" >

   </ListView>

</RelativeLayout>
于 2013-05-24T18:28:52.910 に答える
2

使用するための match_parent の代わりにLinearLayout wrap_content android:layout_height="wrap_content"

于 2013-05-24T18:29:00.687 に答える
0

あなたLinearLayoutが持っandroid:layout_height="match_parent"ているので、それはそれが完全な高さになり、ListViewのためのスペースを残さないことを意味します。

に置き換えwrap_contentます。

于 2013-05-24T18:32:16.367 に答える