android - android 中的 ListView 和操作栏透明

标签 android listview

我的 Activity 中有一个 ListView , Activity 的操作栏中设置为透明和向上导航。结果显示正确,但是第一项显示在 actionBAR 下方。如下图所示:

Check Image Below

下面是我用来使栏透明的代码:

    getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
    ActionBar actionBar = getActionBar();
    actionBar.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
    actionBar.setStackedBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));

    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setDisplayShowHomeEnabled(false);
    setContentView(R.layout.invite_friends);

listView 的invite_friends.XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bluebackground"
android:orientation="vertical" >

<ListView
    android:id="@+id/person_list"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:divider="#b5b5b5"
    android:dividerHeight="1dp"
    android:listSelector="@drawable/list_selector" />

 </LinearLayout>

令人惊讶的是 ListView 认为它是全屏的?如何解决这个问题?

谢谢!

最佳答案

问题是这样的:

getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);

你正在告诉ActionBar处于覆盖模式,这意味着它将覆盖内容而不是位于其上方的固定位置。如果您想动态隐藏和显示ActionBar,这非常有用。在您的应用程序中,但不需要创建 ActionBar透明的。只需将其删除,它就会按您的预期工作。

如果您想要或需要ActionBar在覆盖模式下,您可以将填充应用于 Activity 中的内容等于 ActionBar高度。像这样:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="?android:attr/actionBarSize">
    ...
</RelativeLayout>

如果您使用支持库,则必须使用 ?attr/actionBarSize安装了?android:attr/actionBarSize像这样:

<!-- Support library compatibility -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="?attr/actionBarSize">
    ...
</RelativeLayout>

关于android - android 中的 ListView 和操作栏透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25078212/

相关文章:

.net - WPF ListView 响应于调整列的大小而变宽,但不会收缩

android - 当应用程序在后台时将用户位置更新到服务器

android - 自动短信应用程序崩溃

android - 如何在 Google maps direction api 中获取距离和持续时间

Android,ListView测试代码上的空指针异常

VB.NET ListView 文本更改搜索

java - 共享偏好的持久性

Android:App Widget Configuration Activity 的行为不像 Activity(编辑自:Android:AppWidget not embedding into home screen)

java - 使用 ListView 时 Activity 的奇怪标题损坏

listview - Android ListView 滚动到底部时动态加载更多项目(来自 MysqlDatabase)