2012-02-06 13 views
0

Androidアプリにダイアログボックスを表示して、ユーザーがいくつかのオプションを変更できるようにしたいと考えています。ダイアログ=>スクロールビュー=>展開可能なリストビューのレイアウトはどうすればよいですか?

このダイアログボックスのレイアウトのための私の計画は次のとおりです。

  • ダイアログ
    • ScrollViewすべてのオプション を包む
      • オプショングループ1 - ExpandableListView
      • オプショングループ2 - など上記
      • トップレベルオプションA - CheckedTextView
      • トップレベルのオプションB - CheckedTextView
      • トップレベルのオプションのC - CheckedTextView
    • OK /キャンセルボタン

しかし、私は試してみて、私が終わるレイアウト権を取得ExpandableListViewが最初のグループと同じ高さしか持たないようにオプショングループが折りたたまれているか、ExpandableListViewがダイアログ全体を占めているか、または類似しています。

下のスクリーンショットでは、オプショングループが青色(1つだけ表示)で、トップレベルオプションが緑色で、使用されていないScrollViewスペースが赤色で、OK /キャンセルLinearLayoutが白で表示されます。

Screenshot of bad layout

refine_dialog.xml

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

    <!-- ScrollView so that the user can see all the options 
     Without filling the entire dialog and losing the ok/cancel buttons 
     The height is hardcoded - I'd like to make it fill_parent --> 
    <ScrollView 
     android:background="#FFFF0000" 
     android:layout_weight="0.5" 
     android:layout_width="match_parent" 
     android:layout_height="300dp"> <!--RED--> 

     <!-- Linear layout around the options 
      ScrollView complains if it wraps multiple children --> 
     <LinearLayout 
      android:background="#FF00FF00" 
      android:orientation="vertical" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> <!--GREEN--> 

      <!-- Option groups --> 
      <ExpandableListView 
       android:id="@+id/elvRefine" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:background="#FF0000FF" /> <!--BLUE--> 

      <!-- Top level options --> 
      <CheckedTextView 
       android:id="@+id/checkboxA" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="Top level option A" /> 
      <CheckedTextView 
       android:id="@+id/checkboxB" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="Top level option B" /> 
      <CheckedTextView 
       android:id="@+id/checkboxC" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="Top level option C" /> 

     </LinearLayout> 

    </ScrollView> 

    <!-- OK, cancel buttons --> 
    <LinearLayout 
     android:background="#FFFFFFFF" 
     android:layout_weight="1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:gravity="right"> <!--WHITE--> 
     <Button 
      android:id="@+id/buttonOk" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="OK" /> 
     <Button 
      android:id="@+id/buttonCancel" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Cancel" /> 
    </LinearLayout> 

</LinearLayout> 

getRefineDialog()

private Dialog getRefineDialog() { 
    final Dialog dialog = new Dialog(this); 
    dialog.setContentView(R.layout.refine_dialog); 
    dialog.setTitle("Refine options"); 
    dialog.setCancelable(true); 
    final ExpandableListView elv = 
       (ExpandableListView) dialog.findViewById(R.id.elvRefine); 
    elv.setAdapter(new RefineAdapter(this)); 
    elv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); 
    // cancel button listener 
    Common.setSimpleCancelListener(dialog, R.id.buttonCancel); 
    return dialog; 
} 

ExpandableListView documentationはと言う:あなたは値のラップを使用することはできません

親のサイズも厳密に指定されていない場合は、XMLのExpandableListViewのandroid:layout_height属性の_content(たとえば、親がScrollViewの場合、wrap_contentを指定できませんでした。ただし、ExpandableListView親の特定のサイズ(100ピクセルなど)がある場合は、wrap_contentを使用できます。

...しかし、ScrollViewの固定高さが300dp(または親ダイアログがmatch_parentに設定されている場合はダイアログの固定高さ)が原因で問題になるとは思わなかった。

このレイアウトを正しく動作させる簡単な方法はありますか?そうでない場合は、オプショングループとトップレベルオプションの両方でオプションメニューをどのように表現する必要がありますか?

答えて

0

私はそれ以来、1つのスクロール可能なビューを別のスクロール可能なビューに入れても機能しないという多くの議論を見てきました。私はこれが不可能だと確信しています。

0

あなたのアプリケーションのこの部分をやり直すことを検討してください。ダイアログの内容が多すぎると、ユーザーを混乱させるでしょう。このダイアログは複雑ではなく簡潔で簡単な答えを意味します。

私の提案は、あなたのデザインアプローチを変えています。

+0

同じレイアウトを新しいアクティビティに入れることはできますが、もっと大きなウィンドウで同じ問題が発生することもあります。> http://i.imgur.com/Sa8OG.jpg – George

1

新しいコードでPreferenceActivityとPreferenceFragmentを使用します。この方法では、ホイールを再開発することはなく、アプリはプラットフォーム上の他のユーザーと適合します。

+0

これらを指摘してくれてありがとう、私はAndroidには新しく、彼らについて学ぶのはうれしいです。この場合、ダイアログは検索オプションを絞り込むためのものです。ユーザはテキストで検索し、「オプションを絞り込む」ボタンをクリックする。 1つのカテゴリでは、検索をそれらの状態に制限する州(例えば、アルバータ州、ブリティッシュコロンビア州、マニトバ州)をチェックし、検索結果を同様に制限する他のチェックボックスにチェックを入れることができる。私は、これらのクラスが非永続的/非「設定」タイプのものには適切ではないと考えています - そうですか? – George

関連する問題