android - 如何在 RelativeLayout 或屏幕外稍微显示一个 ImageView?如何在屏幕左上角显示一个橡皮

标签 android android-layout imageview

我已经设置了一个包含所有元素(按钮、图像等)的相对 View 。这是我的 Android 应用程序的标题页。
现在我想在整个布局的左上角覆盖“LITE”横幅。

我的问题是“LITE”横幅图片是一个斜红色的橡胶,我需要在屏幕上将它的左上角点设置为(-45,-45)以仅显示我想要的图像部分(附上源图像以便您了解是什么部分图像的一部分应该在屏幕上可见)。

the banner

我已尝试使用 AbsoluteLayout、RelativeLayout 以编程方式使用 SetLeft 和 SetTop 移动它,但不接受负值。

有什么想法吗?

最佳答案

您可以使用具有属性 android:clipToPadding="false" 的相对布局来获得所需的效果。

示例:

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout  xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clipToPadding="false"
android:background="@android:color/white"
android:paddingLeft="50dip"
>

<ImageView
    android:id="@+id/myId"
    android:layout_width="60dip"
    android:layout_height="60dip"
    android:layout_marginLeft="-70dp"
    android:layout_marginTop="-20dp"
    android:clipChildren="false"
    android:src="@drawable/button_normal" />

</RelativeLayout>

结果:

enter image description here

关于android - 如何在 RelativeLayout 或屏幕外稍微显示一个 ImageView?如何在屏幕左上角显示一个橡皮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24130238/

相关文章:

android - 如何向 SwipeRefreshLayout 内的 listView 添加标题?

android UI从另一个线程更改

java - 隐藏操作栏中的标题并显示图标

android - 渐变不适用于 Lollipop API 21

java - 从 onClickListener 内部处理深度异常

android - 如何在不使用资源的情况下修改字体

android - 高分辨率背景图像在 Android 中带来性能问题

android - 将 Canvas 大小设置为与位图图像相同的大小

android - 在运行时更改语言环境?

android - 如何更改工具栏 subview 的对齐方式