【问题标题】:Triangle hole with drawable带drawable的三角形孔
【发布时间】:2016-02-21 17:47:44
【问题描述】:

B(白色)布局在 A(图像)布局之上,我需要裁剪背景才能得到这个结果。

这可以用drawables吗? 如果没有,其他解决方案是什么?

【问题讨论】:

  • 试试这个解决方案:- stackoverflow.com/a/7317034/1384010
  • "B" 只是 ImageView 内的白色叠加图像(9 个补丁),顶部中间有一个透明切口。
  • Thx @FrankN.Stein,也许您可​​以发布更详细的答案,以便我可以为未来的开发人员验证它?

标签: android overlay crop android-drawable


【解决方案1】:

这是我使用的布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="@drawable/gradient_back"
    android:layout_width="match_parent"
    android:layout_height="166dp"
    >
    <TextView
        android:id="@+id/txtWhiteStripe"
        android:background="@drawable/white_stripe"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="(B) Some text here"
        android:textStyle="bold"
        android:textColor="#f00"
        android:textSize="16sp"
    />
</RelativeLayout>

要得到这个结果 - 好吧,只是一个 proof of a concept,在这里:它可能不是有史以来最吸引人的图形...... ;)

我使用的图片是:

背景 (gradient_back.png) - 我本可以使用单行,但是……我制作了一张完整的图像

白色条纹 (white_stripe.9.png) - 这是概念中最有趣的部分

不幸的是,它几乎不可见,因为它在白色背景上全是白色透明的。

但它真的像这个,在9补丁工具中:

我应该稍微限制内容底部填充 - 但是,通过从右侧移除一些黑色像素很容易做到。

享受吧。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-19
    • 2014-03-25
    • 1970-01-01
    • 2011-03-29
    • 1970-01-01
    • 1970-01-01
    • 2014-05-20
    • 1970-01-01
    相关资源
    最近更新 更多