在我的應用程序中,我有一個自定義對話框,它在頂部顯示一些不需要的邊距,而在xml中,我沒有定義任何類型的邊距或邊距。不過我的對話是這樣的 - 從CustomDialog中減少標題的邊距
爲同一代碼如下 -
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/customDialogRelativeLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dip"
android:layout_marginRight="15dip"
android:textStyle="bold"
android:layout_alignParentTop="true"
android:textColor="@color/white"
android:textSize="22sp"/>
<View
android:id="@+id/view_separator_in_dialog"
style="@style/dialog_separator"
android:layout_width="fill_parent"
android:layout_height="1dip"
android:visibility="gone" />
<TextView
android:id="@+id/tv_message"
style="@style/dialog_message"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone" />
<EditText
android:id="@+id/et_input_text"
style="@style/dialog_edittext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/tv_message"
android:paddingLeft="10dip"
android:visibility="gone" />
<TextView
android:id="@+id/tv_caption"
style="@style/dialog_caption"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/et_input_text"
android:visibility="gone" />
<LinearLayout
android:id="@+id/rl_dialog_buttons_horizontal"
style="@style/dialog_rl_buttons"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="@+id/btn_left_dialog"
style="@style/dialog_button_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:visibility="gone" />
<Button
android:id="@+id/btn_right_dialog"
style="@style/dialog_button_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:visibility="gone" />
</LinearLayout>
</RelativeLayout>
我想,超過了「確認」文本不必要的缺口被刪除。
引發此對話框就像類 -
公共類MyClass的延伸活動{
private View _separator;
private CustomDialogBox _dialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.custom_dialog);
Object[] data = new Object[]{"Confirmation!", "Contact with this number already exits. Do you want to merge?", "Merge", "Create New"};
raiseDailog(this, data);
}
private void raiseDailog(Context context, Object[] data) {
_dialog = new CustomDialogBox(this, data);
_dialog.show();
}
}
而且我CustomDialog類是什麼樣子 -
公共類CustomDialogBox擴展對話{
private TextView _title, _message;
private Button _leftButton, _rightButton;
private View _separator;
private String textviewTop;
private String textviewMiddle;
private String buttonText1;
private String buttonText2;
public CustomDialogBox(Context context, Object[] data) {
super(context);
setContentView(R.layout.custom_dialog);
initializeViews();
fillData(data);
}
private void fillData(Object[] data) {
try {
int i = 0;
textviewTop = (String) data[i++];
textviewMiddle = (String) data[i++];
buttonText1 = (String) data[i++];
buttonText2 = (String) data[i++];
} catch (Exception e) {
e.printStackTrace();
}
generateDialog();
}
private void generateDialog() {
//Title goes here
_title.setVisibility(View.VISIBLE);
_title.setText(textviewTop);
//Separator goes here
_separator.setVisibility(View.VISIBLE);
//Message goes here
_message.setVisibility(View.VISIBLE);
_message.setText(textviewMiddle);
//Ok button goes here
_leftButton.setVisibility(View.VISIBLE);
_leftButton.setText(buttonText1);
//Cancel button goes here
_rightButton.setVisibility(View.VISIBLE);
_rightButton.setText(buttonText2);
}
private void initializeViews() {
_title = (TextView) findViewById(R.id.tv_title);
_message = (TextView) findViewById(R.id.tv_message);
_leftButton = (Button) findViewById(R.id.btn_left_dialog);
_rightButton = (Button) findViewById(R.id.btn_right_dialog);
_separator = findViewById(R.id.view_separator_in_dialog);
}
}
請大家幫忙。
改變你的父佈局的LinearLayout與垂直方向ANS看到任何區別 – waqaslam 2012-03-01 09:17:45
謝謝。但它不工作。同樣的結果。 – Rajkiran 2012-03-01 09:21:08
你可以發佈你如何使用這種佈局的代碼?我相信最大的差距是由於dialogBuilder自己的標題空間 – waqaslam 2012-03-01 09:25:55