コンテンツに合わせてサイズを拡大縮小するAlertDialogを作成しようとしています。テキストコンテンツはダイアログよりも大きくなる可能性があるため、スクロールできる必要があります。私がRelativeLayoutを使用すると、情報がいくらあってもすべてが適切にレンダリングされますが、TextViewを埋めるのに十分なテキストがない場合は、多くの余分なスペースが残ります。これはコードです:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="6dip"
android:paddingLeft="12dip"
android:paddingRight="12dip"
android:paddingBottom="2dip"
>
<CheckBox
android:id="@+id/saleListingCheckbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save sale"
android:textColor="#fff"
android:layout_alignParentBottom="true"
>
</CheckBox>
<ScrollView
android:id="@+id/saleListingLinear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/saleListingCheckbox"
android:layout_alignParentTop="true"
>
<TextView
android:id="@+id/saleListingTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#fff"
android:textSize="7pt"
android:paddingBottom="4dip"
/>
</ScrollView>
</RelativeLayout>
Javaコード:
@Override
protected boolean onTap(int index) {
if (overlays.isEmpty()) {
return false;
}
final SaleOverlayPushPin saleItem = overlays.get(index);
AlertDialog alertDialog = new AlertDialog.Builder(context).create();
alertDialog.setButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
LayoutInflater inflater = context.getLayoutInflater();
dialogView = inflater.inflate(R.layout.sale_listing, null);
textView = (TextView) dialogView.findViewById(R.id.saleListingTextView);
checkbox = (CheckBox) dialogView.findViewById(R.id.saleListingCheckbox);
checkbox.setOnCheckedChangeListener(this);
alertDialog.setView(dialogView);
alertDialog.setTitle(saleItem.getTitle());
textView.setText(saleItem.getSnippet());
checkbox.setTag(saleItem);
checkbox.setChecked(saleItem.isSelected());
alertDialog.show();
return true;
}
そして、これは、データが少なく、データが多い場合の様子です。
LinearLayoutを使用して機能させることができましたが、テキストコンテンツがダイアログよりも大きい場合、チェックボックスがオフになるという別の問題があります。コードとスクリーンショットは次のとおりです。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="6dip"
android:paddingLeft="12dip"
android:paddingRight="12dip"
android:paddingBottom="2dip"
android:orientation="vertical"
>
<ScrollView
android:id="@+id/saleListingLinear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="top"
>
<TextView
android:id="@+id/saleListingTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#fff"
android:textSize="7pt"
android:paddingBottom="4dip"
/>
</ScrollView>
<CheckBox
android:id="@+id/saleListingCheckbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save sale"
android:textColor="#fff"
android:layout_weight="1"
android:layout_gravity="bottom"
>
</CheckBox>
</LinearLayout>
「小さなデータ」の動作はLinearLayoutのように機能し、「大量のデータ」はRelativeLayoutのように機能することをお勧めします。これは可能ですか?
更新:LinearLayoutに対するbartのソリューションは完全に機能します。チェックボックスからlayout_weightを削除することが重要でした。
ただし、RelativeLayoutはまだ期待どおりに機能しません。TextViewのデータが十分に大きい場合、CheckBoxは表示できなくなります。可能であれば、RelativeLayoutのソリューションを知りたいと思います。下記参照: