1

コンテンツに合わせてサイズを拡大縮小する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のソリューションを知りたいと思います。下記参照:

代替テキスト

4

2 に答える 2

3

RelativeLayoutの作業レイアウト(通常、追加のスペースが必要ない場合は、alignParentTopとalignParentBottomを同時に使用しないでください):

<?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"
>

<ScrollView 
    android:id="@+id/saleListingLinear"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"

    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>

<CheckBox 
    android:id="@+id/saleListingCheckbox" 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:text="Save sale"
    android:textColor="#fff"
    android:layout_below="@id/saleListingLinear"
    >
</CheckBox>
</RelativeLayout>

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_gravity="bottom"
    >
</CheckBox>
</LinearLayout>
于 2010-09-03T11:14:17.363 に答える
0

この問題は古いものですが、別の解決策を指摘したいと思います。

この問題が発生したのは、リストビューと下部のボタンが拡大しているためです。

私は AndroidLayoutWeightソリューションのバージョンを使用することになりました。

ListViewとLinearLayout(ボタンを含む)がありました。どうやら、layout_heightを0dpに設定する手法は、ビューにボタンと展開リストの両方を表示させるように機能します。

于 2011-05-26T20:29:59.453 に答える