【发布时间】:2023-04-08 17:37:01
【问题描述】:
我有一个用于对话框主题活动的布局。这正确地呈现。但是,它现在呈现在一个对话框片段中,并且一些视图彼此堆叠。我尝试在顶层添加线性布局,因为我发现了一个建议它的帖子,但这没有帮助。似乎正在跳过将项目标记到其他东西的右侧或左侧的代码,我不知道为什么。任何指导或帮助表示赞赏。
android studio 渲染看起来正确:
布局文件如下
<?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="match_parent">
<RelativeLayout android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/delete_text_overlay"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Delete_Overlay"
android:textColor="#FF000000"
android:onClick="btn_Delete_TextBox_Click"/>
<EditText
android:id="@+id/text_edit_view"
android:layout_below="@id/delete_text_overlay"
android:layout_centerHorizontal="true"
android:textAlignment="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20dp"
android:textColor="@android:color/white"
android:background="#00000000"/>
<Button
android:id="@+id/font_Style_Button"
android:layout_below="@id/text_edit_view"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Font @amp; Style"
android:onClick="fontStyleBtnClick"/>
<TextView
android:id="@+id/center_point_text_edit"
android:layout_below="@id/font_Style_Button"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Button
android:id="@+id/confirm_text_edit"
android:layout_below="@id/font_Style_Button"
android:layout_toLeftOf="@id/center_point_text_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Confirm_Text_Edit_Changes"
android:onClick="btn_Confirm_Changes_Click"/>
<Button
android:id="@+id/cancel_text_edit"
android:layout_below="@id/font_Style_Button"
android:layout_toRightOf="@id/center_point_text_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Cancel_Text_Edit"
android:onClick="btn_Cancel_Changes_Click"/>
</RelativeLayout>
</LinearLayout>
在对话框片段中显示布局的 Java 代码
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.dialog_fragment_text_properties, container, false);
}
创建显示对话框的请求的 Java 代码
void showDialog(dialogTypeEnum dialogType, Bundle tempBundle) {
mStackLevel++;
FragmentTransaction ft = getFragmentManager().beginTransaction();
Fragment prev = getFragmentManager().findFragmentByTag(dialogType.stringValue);
if (prev != null) {
ft.remove(prev);
}
ft.addToBackStack(null);
DialogFragment newFragment;
switch (dialogType){
case DIALOG_FRAGMENT_FONT_PROPERTIES:
newFragment = TextPropertiesDialogFragment.newInstance(tempBundle);
break;
case DIALOG_FRAGMENT_TEXT_EDIT:
newFragment = TextEditDialogFragment.newInstance(tempBundle);
break;
case DIALOG_FRAGMENT_TEXT_PROPERTIES:
//This call
newFragment = TextPropertiesDialogFragment.newInstance(tempBundle);
break;
default:
newFragment = null;
break;
}
if (newFragment != null ){
newFragment.show(ft, dialogType.stringValue);
}
}
【问题讨论】:
-
我在文本中心点文本视图中添加了一个空格,但这没有任何区别。我还尝试将属性 toleftof 和 torightof 更改为 startof 和 toendof。
标签: android layout layout-inflater dialogfragment