【问题标题】:How to prevent the Android title bar from covering the first view item?如何防止Android标题栏覆盖第一个视图项?
【发布时间】:2013-11-12 04:08:09
【问题描述】:

我尝试了一堆不同的排列设置填充、高度等以及不同的布局属性,但仍然无法弄清楚为什么 Android 标题栏会覆盖第一个视图项 (EditText)。

布局 xml 如下所示:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#0099cc"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".Blotter" >

    <EditText
        android:id="@+id/order_entry"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/dummy_order"
        android:keepScreenOn="true"
        android:singleLine="true"
        android:textAlignment="center"
        android:textColor="#33b5e5"
        android:textSize="26sp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/status"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:keepScreenOn="true"
        android:text="@string/dummy_content"
        android:textAlignment="center"
        android:textColor="#33b5e5"
        android:textSize="24sp"
        android:textStyle="bold" />

    <GridView
        android:id="@+id/orders"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/status"
        android:layout_alignParentLeft="true"
        android:layout_below="@id/order_entry" />

</RelativeLayout>

模拟器中的结果是这样的:

有点难看,但我圈出了标题重叠的EditText视图。不过,Eclipse ADT 图形布局视图中的渲染看起来不错。

【问题讨论】:

  • 您在使用 ActionBarSherlock 之类的操作栏库吗?你在使用碎片吗?或使用developer.android.com/reference/android/view/… ?发布有关如何使用该布局的代码。同时,还有一个可能与您的问题有关的问题:stackoverflow.com/questions/19635440/…
  • @frozenkoi:这只是一个基本的入门项目。无ActionBar,一般在创建Eclipse Android 项目时采用默认设置。我很快就会发布代码(但几乎没有什么可看的)。不知何故,只是默认的 Xml 设置并不能阻止标题与第一个视图项重叠。

标签: android android-layout


【解决方案1】:

您尝试使用requestWindowFeature(Window.FEATURE_NO_TITLE); 了吗? 它将在您的 Activity 中以 onCreated 调用,如下所示:

    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_main);

【讨论】:

  • 嗯,我有点喜欢让标题可见...隐藏标题是标准的吗?
  • 上面的那些调用将完全隐藏标题。你的主题有全屏功能吗?因为,我认为内容布局默认在标题下方
  • 项目设置(默认)有android:Theme.Light。
猜你喜欢
  • 1970-01-01
  • 2019-03-14
  • 2010-09-12
  • 2012-09-04
  • 2018-05-13
  • 1970-01-01
  • 2017-03-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多