我正在使用LinearLayout
带有自定义对话框的视图,当我运行下面的代码时,重量无法正常工作,因为红色视图采用绿色视图的重量和虎钳,如下图所示:
但是当我在另一个活动中使用相同的布局时,重量如下图所示:
确认对话框.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>