开发者

Wrong width/height inflating AlertDialog from XML

开发者 https://www.devze.com 2023-02-08 23:29 出处:网络
I\'m having problems inflating an AlertDialog with a custom XML. The problem is that it doesn\'t respect the width/height I\'ve specified.

I'm having problems inflating an AlertDialog with a custom XML. The problem is that it doesn't respect the width/height I've specified.

volume.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:paddingLeft="6dp" android:gravity="center"
    android:layout_gravity="center_horizontal" android:orientation="vertical"
    android:layout_height="wrap_content" android:layout_width="250dip"
    android:id="@+id/layoutRoot">
    <TextView android:layout_width="wrap开发者_开发问答_content"
        android:layout_gravity="left" android:id="@+id/textView1"
        android:layout_height="wrap_content" android:text="Volume:"
        android:layout_marginBottom="10dp" android:textSize="22dp"
        android:layout_marginTop="10dp"></TextView>
    <SeekBar android:layout_height="wrap_content"
        android:layout_width="fill_parent" android:id="@+id/volumeBar"
        android:minHeight="10dp" android:maxHeight="15dp" android:paddingLeft="10dp"></SeekBar>
    <TextView android:layout_width="wrap_content"
        android:layout_gravity="left" android:layout_height="wrap_content"
        android:layout_marginBottom="10dp" android:textSize="22dp"
        android:text="20%" android:id="@+id/volumeText"></TextView>
</LinearLayout>

Code:

    Builder alertbox = new AlertDialog.Builder(this);
    AlertDialog alertDialog;

    LayoutInflater mInflater = (LayoutInflater) this
    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View VolumeView = mInflater.inflate(
            R.layout.volume, (ViewGroup) findViewById(R.id.layoutRoot));
    alertbox.setView(VolumeView);
    alertDialog = alertbox.create();
    alertDialog.show();


Your problem may be the layoutRoot you are providing as the second parameter of your call to mInflater.inflate(). This will affect the layout of the XML file being inflated.

Your question needs more information for anyone to give a better answer than this.

0

精彩评论

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