删除顶部的Android警报对话框空白 [英] Remove Android alert dialog empty space at the top

查看:80
本文介绍了删除顶部的Android警报对话框空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Android布局,用于显示带有关闭"按钮的关于应用"警报对话框.它的标题以粗体居中,并包含应用程序版本和开发人员名称.一切看起来都很好,除了标题上方有一个非常明显的边距/边距,而且我无法删除该空白区域.

I have an Android layout that's used for showing an "about app" alert dialog with a "Close" button. It has a title in bold centered, the app version and the developer name. Everything looks fine except that there's a very noticeable margin/padding above the title and I can't remove that empty space.

这是布局:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:orientation="vertical" android:scrollbars="none" android:layout_width="fill_parent" android:layout_height="wrap_content" xmlns:android="http://schemas.android.com/apk/res/android">
  <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginRight="6.0dp" xmlns:android="http://schemas.android.com/apk/res/android">

    <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:layout_gravity="center">
      <TextView android:textSize="16.0dip" android:textStyle="bold" android:textColor="#ffffffff" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="6.0dip" android:layout_marginRight="6.0dip" android:layout_marginBottom="10.0dip" android:text="@string/app_name" />
    </LinearLayout>

    <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal">
        <TextView android:textSize="14.0dip" android:textColor="#ffffffff" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="6.0dip" android:layout_marginTop="0.0dip" android:text="@string/version_text" />
        <TextView android:textSize="14.0dip" android:textColor="#ffffffff" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="6.0dip" android:layout_marginTop="0.0dip" android:text="@string/app_version" />
    </LinearLayout>

    <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical">
      <TextView android:textSize="14.0dip" android:textColor="#ffffffff" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="6.0dip" android:text="@string/about_developer" />
    </LinearLayout>

    <LinearLayout android:gravity="center" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="10.0dip" xmlns:android="http://schemas.android.com/apk/res/android">
      <Button android:id="@id/close_btn" android:layout_width="110.0dip" android:layout_height="44.0dip" android:layout_marginTop="4.0dip" android:layout_marginBottom="4.0dip" android:text="@string/about_close" />
    </LinearLayout>

  </LinearLayout>
</ScrollView>

这是它的显示内容:

我尝试在许多标签中添加android:layout_marginTop="-10.0dip"属性,并在SO中搜索了类似的问题,但找不到.如果有人向我展示如何解决此问题,我将不胜感激.

I have tried adding android:layout_marginTop="-10.0dip" attribute in many tags and searched SO for a similar issue but I can't find it. I'd be thankful if someone shows me how solve this problem.

推荐答案

您可以尝试通过使用DialogFragment并设置此对话框来使用自定义视图创建自己的对话框

You could try to make your own Dialog with a custom View by using a DialogFragment and set this

dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

或者也许只是尝试使用简单的Dialog,而不是像这样的AlertDialog

Or maybe just try to use a simple Dialog, not an AlertDialog like this

Dialog dialog = new Dialog(theContext);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(yourCustomView);
dialog.show();

这篇关于删除顶部的Android警报对话框空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆