Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/209.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 对话框工作不正常_Android_Dialog - Fatal编程技术网

Android 对话框工作不正常

Android 对话框工作不正常,android,dialog,Android,Dialog,我希望实现以下设计: 这五个选项在单击图像视图时显示。我正在使用对话框实现此设计 1.moreOption.xml <?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=

我希望实现以下设计:

这五个选项在单击图像视图时显示。我正在使用对话框实现此设计

1.moreOption.xml

    <?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"
    android:orientation="vertical"
    android:weightSum="1">

    <TextView
        android:id="@+id/viewContacts"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight=".2"
        android:gravity="center_vertical"
        android:paddingLeft="@dimen/margin10"
        android:text="View Contacts"
        android:textSize="20sp" />

    <View
        android:layout_width="fill_parent"
        android:layout_height="2dp"
        android:background="#c0c0c0" />

    <TextView
        android:id="@+id/archiveChat"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight=".2"
        android:gravity="center_vertical"
        android:paddingLeft="@dimen/margin10"
        android:text="Archive Chat"
        android:textSize="20sp" />

    <View
        android:layout_width="fill_parent"
        android:layout_height="2dp"
        android:background="#c0c0c0" />

    <TextView
        android:id="@+id/deleteChat"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight=".2"
        android:gravity="center_vertical"
        android:paddingLeft="@dimen/margin10"
        android:text="Delete Chat"
        android:textSize="20sp" />

    <View
        android:layout_width="fill_parent"
        android:layout_height="2dp"
        android:background="#c0c0c0" />

    <TextView
        android:id="@+id/markAsUnread"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight=".2"
        android:gravity="center_vertical"
        android:paddingLeft="@dimen/margin10"
        android:text="Mark as unread"
        android:textSize="20sp" />

    <View
        android:layout_width="fill_parent"
        android:layout_height="2dp"
        android:background="#c0c0c0" />

    <TextView
        android:id="@+id/emailChat"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight=".2"
        android:gravity="center_vertical"
        android:paddingLeft="@dimen/margin10"
        android:text="Email Chat"
        android:textSize="20sp" />
</LinearLayout>
    <?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"
    android:orientation="vertical"
    android:weightSum="1">

    <TextView
        android:id="@+id/viewContacts"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/margin10"
        android:layout_weight=".2"
        android:gravity="center_vertical"
        android:paddingLeft="@dimen/margin10"
        android:text="View Contacts"
        android:textSize="20sp" />

    <View
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:layout_marginTop="@dimen/margin10"
        android:background="#c0c0c0" />

    <TextView
        android:id="@+id/archiveChat"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/margin10"
        android:layout_weight=".2"
        android:gravity="center_vertical"
        android:paddingLeft="@dimen/margin10"
        android:text="Archive Chat"
        android:textSize="20sp" />

    <View
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:layout_marginTop="@dimen/margin10"
        android:background="#c0c0c0" />

    <TextView
        android:id="@+id/deleteChat"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/margin10"
        android:layout_weight=".2"
        android:gravity="center_vertical"
        android:paddingLeft="@dimen/margin10"
        android:text="Delete Chat"
        android:textSize="20sp" />

    <View
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:layout_marginTop="@dimen/margin10"
        android:background="#c0c0c0" />

    <TextView
        android:id="@+id/markAsUnread"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/margin10"
        android:layout_weight=".2"
        android:gravity="center_vertical"
        android:paddingLeft="@dimen/margin10"
        android:text="Mark as unread"
        android:textSize="20sp" />

    <View
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:layout_marginTop="@dimen/margin10"
        android:background="#c0c0c0" />

    <TextView
        android:id="@+id/emailChat"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/margin10"
        android:layout_marginTop="@dimen/margin10"
        android:layout_weight=".2"
        android:gravity="center_vertical"
        android:paddingLeft="@dimen/margin10"
        android:text="Email Chat"
        android:textSize="20sp" />


</LinearLayout>
现在单击imageview,我得到以下屏幕截图

但是使用dialog,我并没有按照给定的设计获得更多的空间。请指导我如何实现给定的设计

编辑的代码

我已经解决了这个问题。实际上对话框显示的是空标题。我已经更改了代码,如下所示:

imgMoreOption.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Dialog dialog = new Dialog(context);
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); // hide the title bar
            dialog.setContentView(R.layout.more_option);
            dialog.show();
        }
    });
moreOption.xml

    <?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"
    android:orientation="vertical"
    android:weightSum="1">

    <TextView
        android:id="@+id/viewContacts"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight=".2"
        android:gravity="center_vertical"
        android:paddingLeft="@dimen/margin10"
        android:text="View Contacts"
        android:textSize="20sp" />

    <View
        android:layout_width="fill_parent"
        android:layout_height="2dp"
        android:background="#c0c0c0" />

    <TextView
        android:id="@+id/archiveChat"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight=".2"
        android:gravity="center_vertical"
        android:paddingLeft="@dimen/margin10"
        android:text="Archive Chat"
        android:textSize="20sp" />

    <View
        android:layout_width="fill_parent"
        android:layout_height="2dp"
        android:background="#c0c0c0" />

    <TextView
        android:id="@+id/deleteChat"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight=".2"
        android:gravity="center_vertical"
        android:paddingLeft="@dimen/margin10"
        android:text="Delete Chat"
        android:textSize="20sp" />

    <View
        android:layout_width="fill_parent"
        android:layout_height="2dp"
        android:background="#c0c0c0" />

    <TextView
        android:id="@+id/markAsUnread"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight=".2"
        android:gravity="center_vertical"
        android:paddingLeft="@dimen/margin10"
        android:text="Mark as unread"
        android:textSize="20sp" />

    <View
        android:layout_width="fill_parent"
        android:layout_height="2dp"
        android:background="#c0c0c0" />

    <TextView
        android:id="@+id/emailChat"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight=".2"
        android:gravity="center_vertical"
        android:paddingLeft="@dimen/margin10"
        android:text="Email Chat"
        android:textSize="20sp" />
</LinearLayout>
    <?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"
    android:orientation="vertical"
    android:weightSum="1">

    <TextView
        android:id="@+id/viewContacts"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/margin10"
        android:layout_weight=".2"
        android:gravity="center_vertical"
        android:paddingLeft="@dimen/margin10"
        android:text="View Contacts"
        android:textSize="20sp" />

    <View
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:layout_marginTop="@dimen/margin10"
        android:background="#c0c0c0" />

    <TextView
        android:id="@+id/archiveChat"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/margin10"
        android:layout_weight=".2"
        android:gravity="center_vertical"
        android:paddingLeft="@dimen/margin10"
        android:text="Archive Chat"
        android:textSize="20sp" />

    <View
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:layout_marginTop="@dimen/margin10"
        android:background="#c0c0c0" />

    <TextView
        android:id="@+id/deleteChat"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/margin10"
        android:layout_weight=".2"
        android:gravity="center_vertical"
        android:paddingLeft="@dimen/margin10"
        android:text="Delete Chat"
        android:textSize="20sp" />

    <View
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:layout_marginTop="@dimen/margin10"
        android:background="#c0c0c0" />

    <TextView
        android:id="@+id/markAsUnread"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/margin10"
        android:layout_weight=".2"
        android:gravity="center_vertical"
        android:paddingLeft="@dimen/margin10"
        android:text="Mark as unread"
        android:textSize="20sp" />

    <View
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:layout_marginTop="@dimen/margin10"
        android:background="#c0c0c0" />

    <TextView
        android:id="@+id/emailChat"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/margin10"
        android:layout_marginTop="@dimen/margin10"
        android:layout_weight=".2"
        android:gravity="center_vertical"
        android:paddingLeft="@dimen/margin10"
        android:text="Email Chat"
        android:textSize="20sp" />


</LinearLayout>

您可以这样做:

<?xml version="1.0" encoding="utf-8"?>
  <RelativeLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/activity_main"
    tools:context="com.pathfinder.myapplication.MainActivity">
    <TextView
        android:layout_marginTop="16dp"
        android:layout_marginBottom="16dp"
        android:id="@+id/viewContacts"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight=".2"
        android:gravity="center_vertical"
        android:paddingLeft="16dp"
        android:text="View Contacts"
        android:textSize="20sp" />

    <View
        android:id="@+id/view1"
        android:layout_below="@+id/viewContacts"
        android:layout_width="fill_parent"
        android:layout_height="2dp"
        android:background="#c0c0c0" />

    <TextView
        android:layout_marginTop="16dp"
        android:layout_marginBottom="16dp"
        android:layout_below="@+id/view1"
        android:id="@+id/archiveChat"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight=".2"
        android:gravity="center_vertical"
        android:paddingLeft="16dp"
        android:text="Archive Chat"
        android:textSize="20sp" />

    <View
        android:id="@+id/view2"
        android:layout_below="@+id/archiveChat"
        android:layout_width="fill_parent"
        android:layout_height="2dp"
        android:background="#c0c0c0" />

    <TextView
        android:layout_marginTop="16dp"
        android:layout_marginBottom="16dp"
        android:layout_below="@+id/view2"
        android:id="@+id/deleteChat"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight=".2"
        android:gravity="center_vertical"
        android:paddingLeft="16dp"
        android:text="Delete Chat"
        android:textSize="20sp" />

    <View
        android:id="@+id/view3"
        android:layout_below="@id/deleteChat"
        android:layout_width="fill_parent"
        android:layout_height="2dp"
        android:background="#c0c0c0" />

    <TextView
        android:layout_marginTop="16dp"
        android:layout_marginBottom="16dp"
        android:layout_below="@id/view3"
        android:id="@+id/markAsUnread"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight=".2"
        android:gravity="center_vertical"
        android:paddingLeft="16dp"
        android:text="Mark as unread"
        android:textSize="20sp" />

    <View
        android:id="@+id/view4"
        android:layout_below="@+id/markAsUnread"
        android:layout_width="fill_parent"
        android:layout_height="2dp"
        android:background="#c0c0c0" />

    <TextView
        android:layout_marginTop="16dp"
        android:layout_marginBottom="16dp"
        android:layout_below="@id/view4"
        android:id="@+id/emailChat"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight=".2"
        android:gravity="center_vertical"
        android:paddingLeft="16dp"
        android:text="Email Chat"
        android:textSize="20sp" />

</RelativeLayout>

您可以这样做:

<?xml version="1.0" encoding="utf-8"?>
  <RelativeLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/activity_main"
    tools:context="com.pathfinder.myapplication.MainActivity">
    <TextView
        android:layout_marginTop="16dp"
        android:layout_marginBottom="16dp"
        android:id="@+id/viewContacts"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight=".2"
        android:gravity="center_vertical"
        android:paddingLeft="16dp"
        android:text="View Contacts"
        android:textSize="20sp" />

    <View
        android:id="@+id/view1"
        android:layout_below="@+id/viewContacts"
        android:layout_width="fill_parent"
        android:layout_height="2dp"
        android:background="#c0c0c0" />

    <TextView
        android:layout_marginTop="16dp"
        android:layout_marginBottom="16dp"
        android:layout_below="@+id/view1"
        android:id="@+id/archiveChat"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight=".2"
        android:gravity="center_vertical"
        android:paddingLeft="16dp"
        android:text="Archive Chat"
        android:textSize="20sp" />

    <View
        android:id="@+id/view2"
        android:layout_below="@+id/archiveChat"
        android:layout_width="fill_parent"
        android:layout_height="2dp"
        android:background="#c0c0c0" />

    <TextView
        android:layout_marginTop="16dp"
        android:layout_marginBottom="16dp"
        android:layout_below="@+id/view2"
        android:id="@+id/deleteChat"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight=".2"
        android:gravity="center_vertical"
        android:paddingLeft="16dp"
        android:text="Delete Chat"
        android:textSize="20sp" />

    <View
        android:id="@+id/view3"
        android:layout_below="@id/deleteChat"
        android:layout_width="fill_parent"
        android:layout_height="2dp"
        android:background="#c0c0c0" />

    <TextView
        android:layout_marginTop="16dp"
        android:layout_marginBottom="16dp"
        android:layout_below="@id/view3"
        android:id="@+id/markAsUnread"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight=".2"
        android:gravity="center_vertical"
        android:paddingLeft="16dp"
        android:text="Mark as unread"
        android:textSize="20sp" />

    <View
        android:id="@+id/view4"
        android:layout_below="@+id/markAsUnread"
        android:layout_width="fill_parent"
        android:layout_height="2dp"
        android:background="#c0c0c0" />

    <TextView
        android:layout_marginTop="16dp"
        android:layout_marginBottom="16dp"
        android:layout_below="@id/view4"
        android:id="@+id/emailChat"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight=".2"
        android:gravity="center_vertical"
        android:paddingLeft="16dp"
        android:text="Email Chat"
        android:textSize="20sp" />

</RelativeLayout>

您应该删除
对话框的标题栏

使用

对于
TextView
s,您可以使用一种android预定义样式或自定义样式

将其添加到xml文件中的
TextView
s

style="?android:attr/listSeparatorTextViewStyle"

您应该删除
对话框的标题栏

使用

对于
TextView
s,您可以使用一种android预定义样式或自定义样式

将其添加到xml文件中的
TextView
s

style="?android:attr/listSeparatorTextViewStyle"
1) 当您使用
weight
时,如果将
文本视图中的
android:layout\u height=“wrap\u content”
更改为
android:layout\u height=“0dp”
,效果会更好

2) 添加
requestWindowFeature(窗口.功能\u无\u标题)删除标题栏/布局(空白区域)

PS:如果你在
线性布局中使用固定高度,文本视图的固定高度会更好。

1)当你在使用
重量时,如果你将
安卓:布局高度=“包装内容”
更改为
安卓:布局高度=“0dp”会更好
在您的
文本视图中

2) 添加
requestWindowFeature(窗口.功能\u无\u标题)删除标题栏/布局(空白区域)


PS:最好使用固定高度的
线性布局
文本视图
的固定高度。

您的
文本视图
-s顶部和底部没有衬垫。您的
文本视图
-s顶部和底部可能没有衬垫。您的
文本视图
-s可能重复