问题描述
第一个图像是从Galaxy Note的,第二个是从的Droid 3,他们都从下面的code生产。
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的对话有显著量的额外的,丑陋的空间。这个空间甚至更复杂的对话框丑陋。有没有什么办法prevent呢?
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的用户界面自定义开车送我疯了!
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:
首先,实例化你的对话是这样的(或更好,创建可扩展对话框的自定义类,所以你可以重复使用它):
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>
如果你真的想要得到花式,您可以尝试使用这样的SO回答应用投影到dialog_layout在code:的
这篇关于机器人:对话在Droid 3的额外的,丑陋的空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!