0

这是我第一次在这里发布问题,所以请原谅我的错误。我目前正在开发一个 Android 应用程序,我对它相当陌生。在我的主要活动中,我有一个图像背景和三个按钮。第三个按钮的动作监听器创建一个意图并启动一个新的活动,这是一个自定义的多列列表视图。

问题是当listview Activity启动并变得可见时,主Activity图片背景和上面的三个按钮就变成了listview Activity的背景(这三个按钮是不交互的)。我可以很好地看到列表视图的行。我不确定我会改变什么来摆脱 listview 活动背景中的主要活动。如果其他人遇到此问题,我已尝试在网上搜索,但找不到任何相关内容。如果不清楚,请告诉我是否可以进一步解释。谢谢这是我的布局文件:主要活动布局定义:

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

<TextView
    android:id="@+id/tvStatus"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:layout_marginTop="20dp"
    android:text="@string/tvStatus"
    android:textColor="#000000"
    android:textSize="20sp" />

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <Button
        android:id="@+id/btnClockIn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:text="@string/btnClockIn"
        android:textColor="#000000" />

    <Button
        android:id="@+id/btnClockOut"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/btnClockIn"
        android:layout_centerHorizontal="true"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:text="@string/btnClockOut"
        android:textColor="#000000" />

    <Button
        android:id="@+id/btnViewHours"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/btnClockOut"
        android:layout_centerHorizontal="true"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:text="@string/btnViewHours"
        android:textColor="#000000" />
</RelativeLayout>

</LinearLayout>

ListView 行布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/listViewLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<TextView
    android:id="@+id/displayClockIn"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="2"
    android:text="@string/displayTimeIn"
    android:textColor="#000000" >
</TextView>

<TextView
    android:id="@+id/displayClockOut"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="2"
    android:text="@string/displayTimeOut"
    android:textColor="#000000" >
</TextView>

<TextView
    android:id="@+id/displayHours"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:text="@string/displayHours"
    android:textColor="#000000" >
</TextView>

</LinearLayout>

第二个活动(ListView)布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

 <ListView
    android:id="@+id/listView"
    android:layout_height="wrap_content"
    android:layout_width="match_parent">
</ListView>

</LinearLayout>

下面是我如何为将我带到第二个活动的按钮编写侦听器:

final Button btnViewHours = (Button) findViewById(R.id.btnViewHours);
    btnViewHours.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View the_view) {
            Intent intent = new Intent(MainActivity.this, ViewHoursActivity.class);
            startActivity(intent);
        }

    });
4

1 回答 1

0

您的第二个活动似乎缺少背景或透明背景。

要确定原因,请将以下内容添加到第二个Activity's <LinearLayout>

android:background="@android:color/background"

看看这是否有效。如果没有,请尝试

android:background="@android:color/black"

如果前者有效,则您的 Activity 主题设置不正确,如果第二个有效,则您的主题可能已损坏。

于 2014-05-18T22:57:02.310 回答