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