开发者

Preventing an AlertDialog filling the screen

开发者 https://www.devze.com 2023-03-22 13:43 出处:网络
I am opening an Alert Dialog and all the data is displayed correctly but it is filling the screen The Dialog I am opening is a simple layout and then adding a new layout item within a it 3 times. Tro

I am opening an Alert Dialog and all the data is displayed correctly but it is filling the screen

The Dialog I am opening is a simple layout and then adding a new layout item within a it 3 times. Trouble is the dialog is opening up almost full screen even though the layouts only fill half the screen

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);

   开发者_如何学Go             ll.addView(layoutItem);

                // code setting the textviews
            }

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

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

EDIT

Preventing an AlertDialog filling the screen

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>


Use wrap_content in your inflated xml for the layout

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号