防止AlertDialog填满屏幕

时间:2011-07-22 20:07:24

标签: android xml alertdialog

我正在打开一个警报对话框,所有数据都正确显示,但它正在填满屏幕

我打开的对话框是一个简单的布局,然后在其中添加一个新的布局项目3次。麻烦是对话框几乎全屏打开,即使布局只填满屏幕的一半

LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            final View layout = inflater.inflate(R.layout.layout, (ViewGroup) findViewById(R.id.layout));
            LinearLayout ll = (LinearLayout) layout.findViewById(R.id.layout_lookup);

            for (int i = 0; i < 3; i++) {
                View layoutItem = (View) inflater.inflate(R.layout.layout_item, null);
                TextView Name = (TextView) layoutItem .findViewById(R.id.name);
                TextView Value1 = (TextView) layoutItem .findViewById(R.id.value1);
                TextView Value2 = (TextView) layoutItem .findViewById(R.id.value2);

                ll.addView(layoutItem);

                // code setting the textviews
            }

            //iValue = bundle.getInt("iValue");

            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setView(layout);

修改

AlertDialog Image

Lookup.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="wrap_content"
    android:padding="10dip"
    android:background="@drawable/border_main"
    android:id="@+id/lookup">
</LinearLayout>

lookup_item.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="wrap_content"
        android:padding="10dip"
        android:background="@drawable/border_small"
        android:id="@+id/lookup_item">
        <LinearLayout 
            android:layout_width="match_parent" 
            android:layout_height="wrap_content">
            <TextView 
                android:text=" -- " 
                android:id="@+id/distance"
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content"
                android:textStyle="bold">
            </TextView>
        </LinearLayout>

        <LinearLayout 
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <TableLayout 
                android:layout_height="wrap_content" 
                android:layout_width="match_parent" 

            android:id="@+id/tableLayout"
            android:gravity="center_vertical">
            <TableRow 
                android:id="@+id/tableRow" 
                android:layout_width="match_parent" 
                android:layout_height="wrap_content">
                <textView items>
            </TableRow>
        </TableLayout>
    </LinearLayout>
</LinearLayout>

1 个答案:

答案 0 :(得分:0)

在充气的xml中使用wrap_content作为布局