Android: Dialogs have extra, ugly space on droid 3?(Android:对话框在 droid 3 上有额外的、丑陋的空间?)
问题描述
第一张图片来自 Galaxy Note,第二张来自 Droid 3.它们都由以下代码生成.
The first image is from a Galaxy Note, the second is from a Droid 3. Both of them produced from the below code.
Droid 3 上的对话框有大量额外的、难看的空间.这个空间在更复杂的对话框上更加丑陋.有什么办法可以预防吗?
The dialog on the Droid 3 has a significant amount of extra, ugly space. This space is even uglier on more complex dialogs. Is there any way to prevent it?
public void onCreate(Bundle bundle)
{
super.onCreate(bundle);
TextView tv = new TextView(this);
tv.setText("Hello!");
Dialog dialog = new Dialog(this);
dialog.setContentView(tv);
dialog.setTitle("Hi!");
dialog.show();
}
推荐答案
这些 Droid UI 定制让我抓狂!
These Droid UI customizations drive me crazy!
如果您想控制您的对话框以使它们在设备之间保持一致,您可以使用提供样式参数的构造函数将它们简化为基础.以下示例给出了一个如下所示的对话框:
If you'd like to control your dialogs to make them consistent across devices, you can strip them down to the basics with a constructor that supplies a style parameter. The following example gives a dialog that looks like this:
首先,像这样实例化您的对话框(或者更好的是,创建一个扩展 Dialog 的自定义类,以便您可以重用它):
First, instantiate your dialog like this (or better yet, create a custom class that extends Dialog so you can reuse it):
Dialog dialog = new Dialog(context, android.R.style.Theme_Translucent_NoTitleBar);
dialog.setContentView(R.layout.custom_dialog_layout);
然后,提供一个 custom_dialog_layout.xml(可能看起来像这样):
Then, supply a custom_dialog_layout.xml (could look something like this):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root"
style="@style/VerticalLinearLayout"
android:background="@android:color/transparent"
android:gravity="center_vertical|center_horizontal" >
<LinearLayout
android:id="@+id/dialog_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="@drawable/dialog_background"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:textColor="@android:color/white"
android:text="Hi!" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:textColor="@android:color/white"
android:text="Hello!" />
</LinearLayout>
</LinearLayout>
dialog_background.xml 看起来像这样:
where dialog_background.xml looks something like this:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<corners android:radius="10dp" />
<stroke
android:width="1dp"
android:color="@android:color/black" />
<gradient
android:angle="0"
android:startColor="@android:color/white"
android:endColor="@android:color/white" />
</shape>
如果你真的想变得花哨,你可以尝试使用类似这样的答案在代码中对 dialog_layout 应用阴影:https://stackoverflow.com/a/3723654/475217
And if you really want to get fancy, you could try applying a drop shadow to the dialog_layout in code using something like this SO answer: https://stackoverflow.com/a/3723654/475217
这篇关于Android:对话框在 droid 3 上有额外的、丑陋的空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Android:对话框在 droid 3 上有额外的、丑陋的空间?
基础教程推荐
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01