1

如何删除左侧,右侧和上方对话视图中的空格以重新调整下面的对话框大小?如何删除DialogueFragment中的多余空格?

或以另一种方式如何使这个对话只占据红色的矩形? 在此先感谢。

enter image description here

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类

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); 
} 

}

+0

您已在布局中提供了填充和边距。删除那些则不会有任何间距。只在需要的地方使用。 – Tauqir

+1

我删除了按钮和textview的填充 – Error

回答

0

添加下面这些行

TextView titleTextView = (TextView) this.getDialog().findViewById(android.R.id.title); 
titleTextView.setGravity(Gravity.CENTER); 

这会让你的对话片段的标题访问,您可以自定义它。

相关问题