4

その1つのボタンと1つのリストビュー内で線形レイアウトを使用しています..リストビューは実行時にその項目を動的に追加しています..そのとき、ボタンはリストビューの背後にあり、表示されず、リストビューは全体に収まりますレイアウト。

リストビューの上にボタンを配置したいのですが、リストビューを読み込んだ後もそのままにしておく必要があります

前もって感謝します

私の.xmlファイルは次のとおりです。

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:orientation="vertical"
    android:background="#000000">


    <Button
        android:id="@+id/btn_searchNewDevices"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dip"
        android:layout_gravity="left"
        android:background="#000000"
        android:textColor="#FFFFFF"
        android:text="Search New Devices"
      />   

     <ListView
        android:id="@+id/lst_add_newDevices"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scrollbars="horizontal" >

    </ListView>
</LinearLayout>

ここに画像の説明を入力

ここに新しいデバイスの検索ボタンがあります。

そのボタンをクリックして Bluetooth を検索し、リストビューに追加します ここに画像の説明を入力

これは私のアプリケーションで起こることです..

4

4 に答える 4

1

これでもうまくいくと思います。ぜひお試しください

編集...

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

    <Button
        android:id="@+id/btn_searchNewDevices"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:layout_marginTop="5dip"

        android:text="Search New Devices"
        android:textColor="#000000" />

    <ListView
        android:id="@+id/lst_add_newDevices"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/btn_searchNewDevices" 
        android:scrollbars="horizontal">
    </ListView>

</RelativeLayout>

活動は以下の通りです。

public class MainActivity extends Activity implements OnClickListener {
    ArrayAdapter<String> adapter;
    private Button mBTNSearch;
    private static ListView mLV_list;
    ArrayList<String> devicesList;
    SparseBooleanArray checked;
    RelativeLayout layout;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mBTNSearch = (Button) findViewById(R.id.btn_searchNewDevices);
        devicesList = new ArrayList<String>();

        mLV_list = (ListView) findViewById(R.id.lst_add_newDevices);
        adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, devicesList);
        mBTNSearch.setOnClickListener(this);
      mLV_list.setAdapter(adapter);
    }

    public void onClick(View v) {

        adapter.add("new Device");
        adapter.notifyDataSetChanged();
    }

}

出力キャプチャは次のとおりです

ここに画像の説明を入力してください

于 2012-10-28T08:54:24.480 に答える
0

レイアウトでこのコードを試してください。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />
</LinearLayout>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ListView
        android:id="@+id/listView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
       >
    </ListView>
</LinearLayout>

于 2012-10-29T05:38:07.473 に答える
0

android:layout_weight="1"ボタンが常に画面に表示されるように、リストビューの高さで使用してみてください。

試してみてください:

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000"
    android:orientation="vertical" >
    <Button
        android:id="@+id/btn_searchNewDevices"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:layout_marginTop="5dip"
        android:background="#000000"
        android:text="Search New Devices"
        android:textColor="#FFFFFF" />
    <ListView
        android:id="@+id/lst_add_newDevices"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:scrollbars="horizontal" >
    </ListView>
</LinearLayout>

または、ListView のaddHeaderView()メソッドを使用できます。これはそのためのチュートリアルです。

于 2012-10-28T08:30:25.973 に答える
0

リストビューをスクロールビューの中に入れてみてください。

<Button
    android:id="@+id/btn_searchNewDevices"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="left"
    android:layout_marginTop="5dip"
    android:background="#000000"
    android:text="Search New Devices"
    android:textColor="#FFFFFF" />

<ScrollView
    android:id="@+id/scroll"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_margin="7dip"
    android:scrollbars="none" >

    <ListView
        android:id="@+id/lst_add_newDevices"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scrollbars="horizontal" >
    </ListView>
</ScrollView>

それはうまくいくかもしれません。私はテストしていないので、確かではありません。

于 2012-11-21T04:27:51.890 に答える