如何删除左侧,右侧和上方对话视图中的空格以重新调整下面的对话框?
或以另一种方式如何使这个对话只占据红色矩形? 提前谢谢。
XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:weightSum="5">
<EditText
android:layout_width="200dp"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:layout_gravity="center_horizontal"
android:inputType="numberDecimal"
android:padding="10dp"
style="@style/AlertDialog.AppCompat"
android:hint="enter value"
android:autoText="false"
android:theme="@style/dialog_blue_button" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<Button
style="@style/dialog_blue_button"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="cancel"
android:id="@+id/canel"
android:padding="5dp" />
<Button
style="@style/dialog_blue_button"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:background="@color/red"
android:text="ok"
android:id="@+id/ok"
android:padding="5dp"
android:layout_margin="5dp" />
</LinearLayout>
</LinearLayout>
DialogueFragment class
public class InsertDialogue extends DialogFragment implements View.OnClickListener {
Button ok, cancel;
EditText edit;
Insert communicator;
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
communicator = (Insert) activity;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
setCancelable(false);
getDialog().setTitle("New input");
View view = inflater.inflate(R.layout.insertdialogue, null);
ok = (Button) view.findViewById(R.id.ok);
ok.setOnClickListener(this);
cancel = (Button) view.findViewById(R.id.canel);
cancel.setOnClickListener(this);
edit = (EditText) view.findViewById(R.id.editText);
return view;
}
@Override
public void onClick(View v) {
if (v.getId() == R.id.ok) {
String text = edit.getText().toString();
if (!text.matches("") &&!text.matches("^\\.$") ) {
float s = Float.parseFloat(edit.getText().toString());
if (s > 0) {
communicator.input(s);
dismiss();
}
}
} else {
dismiss();
}
}
interface Insert {
public void input(float Value);
}
}