2011-06-07 34 views
0

以下對話框不受重量參數的影響。有人能解釋爲什麼嗎?對佈局權重無響應的對話框,需要recesitation

可擴展標記語言:


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" android:layout_height="wrap_content" 
    android:weightSum="1" android:orientation="horizontal"> 

    <TextView android:id="@+id/dialogtext" android:layout_width="0dp" 
    android:layout_height="wrap_content" android:layout_weight=".3" /> 
    <Button android:id="@+id/dialogbutton" 
    android:layout_width="0dp" android:layout_weight=".7" 
    android:layout_height="wrap_content" android:text="Cancel" /> 
</LinearLayout> 

的java:


dialog = new Dialog(GameActivity.this); 
dialog.setContentView(R.layout.dialog); 
TextView textdialog = (TextView) dialog.findViewById(R.id.dialogtext); 
textdialog.setText("i dont care what size you want me to be, im comfortable with my body"); 
button = (Button) dialog.findViewById(R.id.dialogbutton); 
button.setOnClickListener(this); 
dialog.show(); 

如果我指定的尺寸到DP,它不過響應。

回答

3

我懷疑你需要將外部LinearLayout的寬度設置爲match_parent。否則,LinearLayout將使自己的寬度足以容納它的子元素,而這些子元素又足夠寬以展示自己。結果沒有額外的寬度與權重分配。

+0

是的,這是它。很簡單。謝謝。 – 2011-06-07 23:59:55

+0

很高興我能幫上忙。 – mportuesisf 2011-06-09 21:49:21