Androidアプリにダイアログボックスを表示して、ユーザーがいくつかのオプションを変更できるようにしたいと考えています。ダイアログ=>スクロールビュー=>展開可能なリストビューのレイアウトはどうすればよいですか?
このダイアログボックスのレイアウトのための私の計画は次のとおりです。
- ダイアログ
- ScrollViewすべてのオプション を包む
- オプショングループ1 - ExpandableListView
- オプショングループ2 - など上記
- トップレベルオプションA - CheckedTextView
- トップレベルのオプションB - CheckedTextView
- トップレベルのオプションのC - CheckedTextView
- OK /キャンセルボタン
- ScrollViewすべてのオプション を包む
しかし、私は試してみて、私が終わるレイアウト権を取得ExpandableListViewが最初のグループと同じ高さしか持たないようにオプショングループが折りたたまれているか、ExpandableListViewがダイアログ全体を占めているか、または類似しています。
下のスクリーンショットでは、オプショングループが青色(1つだけ表示)で、トップレベルオプションが緑色で、使用されていないScrollViewスペースが赤色で、OK /キャンセルLinearLayoutが白で表示されます。
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に設定されている場合はダイアログの固定高さ)が原因で問題になるとは思わなかった。
このレイアウトを正しく動作させる簡単な方法はありますか?そうでない場合は、オプショングループとトップレベルオプションの両方でオプションメニューをどのように表現する必要がありますか?
同じレイアウトを新しいアクティビティに入れることはできますが、もっと大きなウィンドウで同じ問題が発生することもあります。> http://i.imgur.com/Sa8OG.jpg – George