我正在使用带有自定义对话框的LinearLayout
视图,当我运行下面的代码时,重量无法正常工作,因为红色视图将绿色视图的重量和诗歌视为图片如下:
但当我在其他活动中使用相同的布局时,重量正确如下图所示:
ConfirmDialog.java
public class ConfirmDialog extends DialogFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = super.onCreateDialog(savedInstanceState);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
return dialog;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.dialog_confirm, null);
return view;
}
}
dialog_confirm.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="7" >
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="6"
android:background="#00ff00" />
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#ff0000" />
</LinearLayout>