【问题标题】:Android overlay outside/between layout boundariesAndroid 覆盖在布局边界之外/之间
【发布时间】:2015-12-31 19:14:24
【问题描述】:

我必须添加一个叠加层 (ImageView),以便它稍微移动到包含布局的左边界的左侧。

最好的方法是什么?

尝试了一些简单的方法,比如将 ImageView 放在布局中并使用负边距

android:layout_marginLeft="-20dip"

这是这样的:

(更正:图片中的文字应该是 20dip 而不是 20px)

AbsoluteLayout 已弃用。有没有像z-order这样的东西?或者我该怎么办?

提前致谢。

编辑:我尝试使用相对布局。一样的效果。这是 xml 减少到最低限度:

<RelativeLayout  xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clipChildren="false"
android:paddingLeft="50dip"
>

<ImageView
    android:id="@+id/myId"
    android:layout_width="60dip"
    android:layout_height="60dip"
    android:layout_marginLeft="-30dip"
    android:clipChildren="false"
    android:src="@drawable/pic" />

</RelativeLayout>

结果

当包含布局的背景图像小于屏幕而不是填充时也会发生。

【问题讨论】:

    标签: android layout


    【解决方案1】:

    使用 RelativeLayout 而不是 LinearLayout(允许重叠)并将其添加到 RelativeLayout 修复它:

    android:clipToPadding="false"
    

    【讨论】:

      【解决方案2】:

      在 xml 中设置“android:clipChildren = false”

      【讨论】:

      • 没有帮助。我把它放在包含布局和图像视图中,它没有改变任何东西。
      【解决方案3】:

      代替

      android:layout_marginLeft="-30dip"

      试试

      android:paddingLeft="-30dp"

      【讨论】:

        【解决方案4】:

        在宽度 = 30dp 的线性布局左侧使用透明(android:background="#00000000")图像视图。并在相对布局的情况下使 myId 左对齐。如果您使用线性布局,请将方向设为水平,并让透明图像视图成为其中的第一个条目。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2018-07-09
          • 2018-08-20
          • 1970-01-01
          • 2011-04-26
          • 2014-01-31
          • 1970-01-01
          • 2013-03-04
          • 1970-01-01
          相关资源
          最近更新 更多