Android 安卓如何在另一个图像上添加透明图像

Android 安卓如何在另一个图像上添加透明图像,android,xml,splash-screen,Android,Xml,Splash Screen,我知道如何通过surfaceView做到这一点,我想知道我是否应该这样做 我只是尝试创建一个splashscreen,它有一个全屏图像,上面有一个不透明的图像(经过短暂的延迟)。我不知道如何在XML代码中实现这一点 这就是我所拥有的 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orie

我知道如何通过surfaceView做到这一点,我想知道我是否应该这样做

我只是尝试创建一个splashscreen,它有一个全屏图像,上面有一个不透明的图像(经过短暂的延迟)。我不知道如何在XML代码中实现这一点

这就是我所拥有的

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

<ImageView
android:id="@+id/lightDot"
android:src="@drawable/splashlight"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@null"
 />

<ImageView
android:id="@+id/bGround"
android:src="@drawable/splash"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
 />

谢谢。

使用相对布局而不是线性布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:id="@+id/ll"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
***android:background="@drawable/splash"*** >
这允许您将视图放置在彼此的顶部,而不是线性列表中

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

  <ImageView
    android:id="@+id/lightDot"
    android:src="@drawable/splashlight"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@null"
     />

  <ImageView
    android:id="@+id/bGround"
    android:src="@drawable/splash"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
     />

</RelativeLayout>

要使点在时间之后出现,请在xml中使用
android:visiblity=“INVISIBLE”
。(因此它开始隐形)


然后使用
light.setVisibility(View.VISIBLE)在代码中。

使用相对布局而不是线性布局

这允许您将视图放置在彼此的顶部,而不是线性列表中

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

  <ImageView
    android:id="@+id/lightDot"
    android:src="@drawable/splashlight"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@null"
     />

  <ImageView
    android:id="@+id/bGround"
    android:src="@drawable/splash"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
     />

</RelativeLayout>

要使点在时间之后出现,请在xml中使用
android:visiblity=“INVISIBLE”
。(因此它开始隐形)

然后使用
light.setVisibility(View.VISIBLE)在您的代码中。

您需要的是一个

子视图绘制在堆栈中,最新添加的子视图位于顶部

使用
layout\u gravity
,您可以对覆盖的位置更感兴趣,但听起来这就是您所需要的

    <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <ImageView
            android:id="@+id/image"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:src="@drawable/image" >
        </ImageView>

        <ImageView
            android:id="@+id/overlay"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:src="@drawable/overlay"/>
    </FrameLayout>

您想要的是一个

子视图绘制在堆栈中,最新添加的子视图位于顶部

使用
layout\u gravity
,您可以对覆盖的位置更感兴趣,但听起来这就是您所需要的

    <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <ImageView
            android:id="@+id/image"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:src="@drawable/image" >
        </ImageView>

        <ImageView
            android:id="@+id/overlay"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:src="@drawable/overlay"/>
    </FrameLayout>

您可以使用

定义一个简单的线性布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/splash_layout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
你可以用一个

定义一个简单的线性布局

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

尝试重新排序图像视图,或使用框架布局。它可能是以错误的顺序设置在另一个之上的。我认为上面还有一个标签。请尝试重新排序图像视图,或使用框架布局。它可能是以错误的顺序设置在另一个之上的。我想上面还有一个标签。谢谢,我做了一些小的调整,你知道我该如何增加延迟吗?我试过了。试着睡一觉,但这似乎不起作用(将其设置为for循环,并使用for循环中的变量来计算不透明度,但是延迟发生在绘制任何东西之前,而不是减慢动画速度-谢谢,通过一些小的调整就可以实现这一点-知道如何添加延迟吗?我尝试了thread.sleep中的try/catch,但这似乎不起作用(将其放在for循环中,并使用for循环中的变量来计算不透明度,但是延迟发生在绘制任何东西之前,而不是减慢动画速度-谢谢感谢大家的回答,这里有一些好主意,最后,尽管我决定全部用代码而不是XML来完成-看起来简单多了!谢谢nk you all for you答案,这里有一些好主意,最后,尽管我决定用代码而不是XML来完成这一切-看起来简单多了!谢谢