0

連絡先のリスト全体 (長いリスト) を表示する ListView を含むレイアウトを作成する方法が見つからないようです。リストの下に 2 つのボタンが並んでいます。

それは私を怖がらせます、私がしていることは何もうまくいかないようです。私はいくつかの関連する質問を検索し、これを見つけました:ListViewとButtonsを備えたAndroidレイアウト ですが、そこにある代替ソリューションはどれも私のために働いていません.

(Eclipse の) グラフィック表示を見ると問題ないように見えますが、自分のデバイスで実行すると、連絡先のリストしか表示されません。listView はボタンに重なっています。

行を表す別のレイアウトでレンダリングする simpleList を使用しています。Javaコードを実行したところ、話していた activity_contact_list についての言及が見つからなかったため、プログラムで何かが台無しになっているのではないかと疑い始めています。行レイアウトへの接続のみ。

だから私はこの activity_contact_list.xml を手に入れました:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/contact_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
    android:id="@+id/list"
    android:layout_width="match_parent"
    android:layout_alignParentTop="true" >
</ListView>

<LinearLayout
    android:id="@+id/buttons"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_weight="1.0"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/action_cancel"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Cancle" />

    <Button
        android:id="@+id/action_add"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Add" />
</LinearLayout>
</LinearLayout>

これは、LinearLayout の代わりに RelativeLayout を使用する、ボタンの LinearLayout の下に ListView のコードを配置するなど、多くの試行を重ねた結果です。

アクティビティのコードは次のとおりです: ContactList.java:

public class ContactList extends ListActivity{

//some global variables for late use.
public Model model;                         
SimpleAdapter adapter;
List<Map<String, String>> data;             /* data is a list of Map */
String[] from = {"name","phone"};           /* names of the columns */     //TODO - add date!
int[] to = {R.id.name, R.id.number};    
List<Contact> contacts;                     /* list of contacts */


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //  setContentView(R.layout.activity_contact_list);


    // Set up the action bar.
    final ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
    actionBar.setDisplayHomeAsUpEnabled(true);

    model = Model.getInstance(this);

    data = new ArrayList<Map<String, String>>(); 
    contacts = fillContactsList();

    fill_data();
    adapter = new SimpleAdapter(this, data, R.layout.contact_list_row, from, to);
    setListAdapter(adapter);    


}

setContentView他の方法ではコンパイルできないため、その行にコメントを付けました...

言われるとおりです。リストは完全に機能します。ただし、アクティビティの下部にあるボタンと重なっています。何か案が?私はそれが何かばかげていると確信しています..

前もって感謝します!

4

2 に答える 2

1

Relative Layout を使用しようとしましたか?

Linear Layout を Relative Layout に変更するだけです。

線形レイアウトは親の整列をサポートしていないため..

編集済み

リストの高さをマッハの親に設定します。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/contact_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<ListView
    android:id="@+id/list"
    android:layout_below="@+id/buttons"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
</ListView>

<LinearLayout
    android:id="@+id/buttons"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="2" >

    <Button
        android:id="@+id/action_cancel"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Cancle" />

    <Button
        android:id="@+id/action_add"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Add" />
</LinearLayout>

于 2013-08-05T21:05:17.150 に答える
0

ListView の長さ。画面よりも長く、ボタンが画面の外に表示されている LinearLayout かもしれません。

ListView の上にあるボタンで並べ替えるとどうなりますか。

編集: ListView で最大サイズを設定する必要があると思います。Javaコードでこのようなことを試すことができるかもしれませんが、スクロール可能かどうかはわかりません...

ListView listView = (ListView) findViewById(R.id.listView):
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) listView .getLayoutParams();
params.height = 200;    // or something bigger / smaller
listView .setLayoutParams(params);
于 2013-08-05T21:06:50.990 に答える