2011-02-03 45 views
1

我遇到了使用自定義XML膨脹AlertDialog的問題。問題是它不尊重我指定的寬度/高度。錯誤的寬度/高度充氣XML中的AlertDialog

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> 

代碼:

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(); 
+0

我可以請你多一點具體。我的意思是你期望什麼,你看到了什麼? – the100rabh 2011-02-03 19:06:17

回答

0

你的問題可能是layoutRoot您提供爲您的來電mInflater.inflate()的第二個參數。這將影響正在膨脹的XML文件的佈局。

您的問題需要更多信息給任何人比這更好的答案。