2011-01-05 12 views
2

私はアクティビティの一部であるリストビューを持っています。私はユーザがリストビュー内の項目を一括して削除する選択をしたいので、メニューから対応するオプションを選択すると、すべてのリスト項目の横にチェックボックスが表示されます。ユーザーが任意のチェックボックスをクリックすると、ボタンバーが下から上に移動し(gmailアプリケーションのように)、削除ボタンをクリックすると選択したアイテムが削除されますが、バーのキャンセルボタンをクリックするとチェックされたアイテムはすべてオフになります。ボトムボタンバーはListviewの最後の要素と重なっています!

これは私のページ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> 

はこれまでのところ、私は下のバーは、チェックボックスの選択時に表示されたときに、それはリストの最後の要素と重なることを除いて作業のすべてを持っています。他のすべてのリスト項目をスクロールすることはできますが、リストの最後の項目を上にスクロールすることはできません。そのため、ユーザーはその項目を選択することはできません。ここにはscreenshot of the overlapがあります。

私はlistviewフッターオプションを使用しようとしましたが、バーが画面の下に固定されずにリストの末尾に追加されます。オーバーラップが起こらないようにリストビューを十分に「引き上げる」方法がありますか? 私はすでにリストビュー自体にボトムマージンを追加しようとしましたが、ボタンバーを表示する前にリストビューをラップするLinearLayoutがありましたが、リストビューのチェックボックスをクリックするなど、

+0

RelativeLayoutを、ListViewを保持するLinearLayoutと同じ重さのLinearLayoutに置き換えるとどうなりますか? – James

答えて

0

これをテストしませんでしたが、これを引き起こしているFrameLayoutはかなり確信しています:) FrameLayoutはあなたが与えた "重み"に気にしないからです。 FrameLayoutは、挿入したビューを互いに前方に配置するだけです。そして、あなたが与えた2番目のものはアンドロイド:layout_gravity = "bottom"と書いてあります。リストビューからちょうどinfront。 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> 
+0

ヘイ・パトリック!!お手伝いありがとう。それは部分的に働いた。理由は部分的に、私は手作業でボトムマージンを設定する必要がないので、助けになりました。しかし、私はまだビューのマージンを調整することに関連していた問題を抱えています。つまり、1つのチェックマークをクリックすると別のチェックボックスをチェックしようとします。 framelayoutがlistviewの上にボタンバーを追加すると、この問題は表示されません。どのようなアイデアを引き起こす可能性がありますか? – elto

+0

良い質問..なぜそれを推測するのは難しいです。おそらく私はそれを把握しようとすることができるよりも小さな例(その全体のプロジェクトのソース)を共有する場合。 –

0

は思えます。まず、リストビューのサイズが変更されると直ちにそれが再描画されるため、表示可能なすべてのリスト項目に対してgetView()が再度呼び出されるため、問題が発生していました。私はViewHolderを使用しており、ビューが再利用されているので、同じチェックボックスが他のリスト項目に対して再利用されるようです。したがって、私が1つのチェックボックスをクリックすると、代わりに他のチェックボックスがクリックされていました。リストビューをリフレッシュするこの呼び出しは、リストのサイズが変更されているときにのみ発生し、他のチェックボックスが選択されていないときにリストのチェックボックスをオンにするとリストのサイズが変更されるため、 。

問題を解決するには、チェックされたアイテムを保存するカスタムコレクションクラスを作成し、アイテムをこのコレクションに入れる前に、クリックしたチェックボックスのタグとクリックリスナーを新しいチェックボックスにコピーし、コレクション。これは、チェックボックスの奇妙な動作を解決しました。 これは問題の最良の解決策ではない可能性がありますので、これ以上のことが分かっている場合は、共有してください。

関連する問題