【问题标题】:layer application in androidandroid中的层应用程序
【发布时间】:2012-01-11 08:48:52
【问题描述】:

我是 Android 的新手,请原谅我的愚蠢。 好吧,我的问题在于多层 -

我想将两个透明的 ImageView 组合在一起。这类似于 Photoshop 图层,android 中的示例图层活动是什么?

【问题讨论】:

    标签: android


    【解决方案1】:

    您可以为此使用RelativeLayout。

    属性 android:layout_centerInParent 如果为 true,则子元素在其父元素中水平和垂直居中。 [布尔]

    类似的还有 , android:layout_alignParentLeft,

    android:layout_alignParentRight,

    android:layout_alignParentTop,

    android:layout_alignParentBottom.

    试试这些。

    【讨论】:

      【解决方案2】:

      已经回答Overlapping Views in Android ?这应该就是你所需要的,使用RelativeLayout:

      <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
          android:orientation="vertical"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/layout"
      >
      <ImageView android:id="@+id/imageview1"
          android:background="#00000000"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:src="@drawable/image1"
          />
      
       <ImageView android:id="@+id/imageview2"
          android:background="#00000000"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:src="@drawable/image2"
          /> 
      
      </RelativeLayout>
      

      将是您的示例代码。

      【讨论】:

      • 谢谢.. 我试过这段代码,但屏幕仍然是空白的。我应该在代码中添加任何其他内容还是只有这个 xml 文件可以?
      • 您还需要另外 3 个文件:分别为 image1、image2,以及引用 RelativeLayout 的 .java 文件。我也会检查清单,但这是对另一个问题的回答。希望这就够了。
      • 我在 drawable 中添加了三个图像。然后它也不起作用。帮帮我。现在我的应用程序在 main.xml 中有 3 个图像和这个 xml 文件。
      【解决方案3】:

      【讨论】:

        【解决方案4】:

        好吧,在 android 中是完全可以做到的,但实际上你将要使用它。您可以为布局中的两个图像提供相同的位置,现在两者都将重叠,并且根据您的条件或情况,您可以以编程方式显示和隐藏另一个。以同样的方式,您可以提供多个相互重叠的图像。希望这能帮助你理解:)

        【讨论】:

        • 谢谢我试过了,现在可以看到两张图片了。一个高于另一个。我想在背景图像中添加运动事件。我怎样才能做到这一点 ?你能帮帮我吗?
        猜你喜欢
        • 1970-01-01
        • 2020-09-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-04-04
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多