我正在尝试使用Dependency Service在Android上显示一个对话框。但是,我无法显示在android layout designer中创建的设计来显示,结果却有所不同。
这是我的预览器的屏幕截图: Expected design
这是我的结果的屏幕截图: Unexpected result
我的axml代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dialogWrapper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:background="@drawable/backgroundstyle"
android:layout_marginRight="16dp"
android:stateListAnimator="@null">
<TextView
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:paddingTop="16dp"
android:textAlignment="center"
android:textColor="#000"
android:textSize="19sp"
android:text="TitleText"
android:textStyle="bold" />
<TextView
android:id="@+id/subtitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/title"
android:paddingBottom="16dp"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:paddingTop="4dp"
android:textAlignment="center"
android:text="subtitle test"
android:textColor="#000"
android:textSize="15sp" />
<RelativeLayout
android:id="@+id/RL_editTextWrapper"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/subtitle"
android:padding="15dp"
>
<EditText
android:id="@+id/inputText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/roundedentry"
android:paddingBottom="8dp"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:paddingTop="8dp"
android:textAlignment="center"
android:textColor="#000"
android:text="inputText test"
android:textSize="15sp" />
</RelativeLayout>
<View
android:id="@+id/line"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@+id/RL_editTextWrapper"
android:background="#cdced2" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/line"
android:orientation="horizontal">
<TextView
android:id="@+id/dialogButtonNO"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingBottom="12dp"
android:paddingTop="12dp"
android:stateListAnimator="@null"
android:textAlignment="center"
android:textColor="#007aff"
android:text="Cancel"
android:textSize="19sp" />
<View
android:id="@+id/separator"
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#cdced2" />
<TextView
android:id="@+id/dialogButtonOK"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingBottom="12dp"
android:paddingTop="12dp"
android:stateListAnimator="@null"
android:textAlignment="center"
android:textColor="#007aff"
android:textSize="19sp"
android:text="Ok"
android:textStyle="bold" />
</LinearLayout>
@ drawable / backgroundstyle代码:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid
android:color="@android:color/white"/>
<corners
android:radius="16dp" />
这是用于在android中导出依赖项服务的代码:
namespace FFF.Droid.Native {
public class IOSDialogStyleDroid : IIOSDialogStyle {
public void ShowPopup(EntryPopup entryPopup) {
var context = CrossCurrentActivity.Current.Activity as FormsAppCompatActivity;
CustomDialog customDialog = new CustomDialog(context) {
entryPopup = entryPopup
};
customDialog.Show();
}
}
public class CustomDialog : Dialog {
public Context context { get; set; }
public EntryPopup entryPopup { get; set; }
public CustomDialog(Context context) : base(context) {
this.context = context;
}
protected override void OnCreate(Bundle savedInstanceState) {
base.OnCreate(savedInstanceState);
RequestWindowFeature((int)WindowFeatures.NoTitle);
SetContentView(Resource.Layout.iOSStyleDialog);
EditText editText = FindViewById(Resource.Id.inputText) as EditText;
(FindViewById(Resource.Id.title) as TextView).Text = entryPopup.Title;
(FindViewById(Resource.Id.subtitle) as TextView).Text = entryPopup.Message;
var btnOk = FindViewById(Resource.Id.dialogButtonOK) as TextView;
btnOk.Text = entryPopup.okButton;
btnOk.Click += (object sender, EventArgs e) => {
entryPopup.OnPopupClosed(new EntryPopupClosedArgs {
Button = entryPopup.okButton,
Text = editText.Text
});
Dismiss();
};
var btnNo = FindViewById(Resource.Id.dialogButtonNO) as TextView;
btnNo.Text = entryPopup.cancelButton;
btnNo.Click += (object sender, EventArgs e) => {
entryPopup.OnPopupClosed(new EntryPopupClosedArgs {
Button = entryPopup.cancelButton,
Text = editText.Text
});
Dismiss();
};
}
}
答案 0 :(得分:0)
我发现文本对齐方式似乎已损坏,我改用重力。