2

アクティビティの一部であるリストビューがあります。ユーザーがリストビューのアイテムを一括削除することを選択できるようにしたいので、メニューから対応するオプションを選択すると、すべてのリストアイテムの横にチェックボックスが表示されます。ユーザーがチェックボックスをクリックすると、ボタンバーが下から上にスライドし(Gmailアプリのように)、削除ボタンをクリックすると選択したアイテムが削除されますが、バーのキャンセルボタンをクリックするとすべてのチェック済みアイテムのチェックが外れます。

これは私のページlayout.xmlです:

<?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="fill_parent"    
    android:background="@android:color/transparent"
    >

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

    <LinearLayout
      android:id="@+id/list_area"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:layout_weight="1"  
      >
      <ListView
          android:id="@+id/mylist"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:background="@android:color/transparent" 
          android:drawSelectorOnTop="false"
          android:layout_weight="1"
      />

      <TextView
        android:id="@+id/empty_list_message"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textColor="#FFFFFF"
        android:layout_gravity="center_vertical|center_horizontal"
        android:text="@string/msg_for_emptyschd"
        android:layout_margin="14dip"
        android:layout_weight="1"
         />
  </LinearLayout>

  <RelativeLayout
    android:id="@+id/bottom_action_bar"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/schedule_bottom_actionbar_border"
    android:layout_marginBottom="2dip"
    android:layout_gravity="bottom"
    android:visibility="gone"
    >    
    <Button
        android:id="@+id/delete_selecteditems_button"
        android:text="Deleted Selected"
        android:layout_width="140dip"
        android:layout_height="40dip"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="3dip"
        android:layout_marginTop="3dip"
    />

    <Button
    android:id="@+id/cancel_button"
        android:text="Cancel"
        android:layout_width="140dip"
        android:layout_height="40dip"
        android:layout_alignParentRight="true"
        android:layout_marginRight="3dip"
        android:layout_marginTop="3dip"
    />    
     </RelativeLayout>    
   </FrameLayout>        
</LinearLayout>

これまでのところ、チェックボックスを選択すると下部のバーが表示され、リストの最後の要素と重なることを除いて、すべてが機能しています。他のすべてのリストアイテムは上にスクロールできますが、リストの最後のアイテムを上にスクロールすることはできないため、ユーザーは意図した場合にそのアイテムを選択できません。これがオーバーラップのスクリーンショットです

リストビューフッターオプションを使用してみましたが、画面の下部に固定されたままではなく、リストの最後にバーが追加されます。オーバーラップが発生しないようにリストビューを十分に「上げる」方法はありますか?ところで、私はすでにリストビュー自体に下マージンを追加するか、ボタンバーを表示する直前にリストビューをラップするLinearLayoutを追加しようとしましたが、1つのチェックボックスをクリックするとリストビューの別のチェックボックスがチェックされるなどの他のバグが発生します。

4

2 に答える 2

0

これをテストしませんでしたが、これを引き起こしているのはFrameLayoutであると確信しています:)。FrameLayout は、指定した「重み」を気にしないためです。FrameLayout は、挿入したビューを互いの前に配置するだけです。そして、あなたが与えた2番目のものは、 android:layout_gravity="bottom" と言いました。これにより、下部に配置されます。しかし、リストビューのすぐ前です。FrameLayout を削除すると、動作するはずです。

次のようにしてみてください。

<?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="fill_parent" android:background="@android:color/transparent">

    <LinearLayout android:id="@+id/list_area"
        android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1">
        <ListView android:id="@+id/mylist" android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:background="@android:color/transparent"
            android:drawSelectorOnTop="false" android:layout_weight="1" />

        <TextView android:id="@+id/empty_list_message"
            android:layout_width="fill_parent" android:layout_height="wrap_content"
            android:textColor="#FFFFFF" android:layout_gravity="center_vertical|center_horizontal"
            android:text="@string/msg_for_emptyschd" android:layout_margin="14dip"
            android:layout_weight="1" />
    </LinearLayout>

    <RelativeLayout android:id="@+id/bottom_action_bar"
        android:orientation="horizontal" android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:background="@drawable/schedule_bottom_actionbar_border"
        android:layout_marginBottom="2dip"
        android:visibility="gone">
        <Button android:id="@+id/delete_selecteditems_button"
            android:text="Deleted Selected" android:layout_width="140dip"
            android:layout_height="40dip" android:layout_alignParentLeft="true"
            android:layout_marginLeft="3dip" android:layout_marginTop="3dip" />
        <Button android:id="@+id/cancel_button" android:text="Cancel"
            android:layout_width="140dip" android:layout_height="40dip"
            android:layout_alignParentRight="true" android:layout_marginRight="3dip"
            android:layout_marginTop="3dip" />
    </RelativeLayout>

</LinearLayout>
于 2011-01-05T08:49:31.423 に答える
0

奇妙なチェックボックスの動作の問題を解決したようです。まず、リストビューのサイズが変更されるとすぐに再描画されるため、問題が発生していたため、表示されているすべてのリスト項目に対して getView() が再度呼び出されます。私はViewHolderを使用していて、ビューが再利用されているため、同じチェックボックスが他のリスト項目で再び再利用されるようです。そのため、あるチェックボックスをクリックすると、代わりに他のチェックボックスがクリックされました。リストビューを更新するこの呼び出しは、リストのサイズが変更されているときにのみ発生し、他のチェックボックスがマークされていないときにリスト内のチェックボックスをマークしたときにのみリストのサイズが変更されたため、最初のチェックボックスがマークされた後、この問題は再び発生しません.

チェックした項目を保存するカスタム コレクション クラスを作成することで問題を解決し、このコレクションに項目を配置する前に、クリックされたチェックボックスのタグとクリック リスナーを新しいチェックボックスに複製し、その新しいチェックボックスをコレクションに保存します。これにより、チェックボックスの奇妙な動作が解決されました。これは問題の最善の解決策ではない可能性があるため、これよりも良い方法を知っている場合は共有してください.

于 2011-01-07T09:06:10.887 に答える