简体   繁体   English

在Android中绘制自定义可绘制

[英]draw custom drawable in android

How can I draw the custom drawable as attached in the image? 如何绘制图像中附加的自定义可绘制对象?

在此处输入图片说明

I don't the complete code, just steps how should I proceed would be sufficient and any links to advanced custom drawable tutorials. 我没有完整的代码,仅执行我应该如何进行的步骤就足够了,并且任何指向高级自定义可绘制教程的链接。 Thanks. 谢谢。

You can achieve this by using 9-patch images as background. 您可以通过使用9色块图像作为背景来实现。

Here is a nice tool you can use online Simple Nine-patch Generator 这是一个不错的工具,您可以在线使用简单的九补丁生成器

Here is how you would achieve it 这是您将如何实现的

  • Use a White background for your main layout view (Table View for example) 在主布局视图中使用白色背景(例如,表格视图)
  • create two 9-patch images for the grey boxes. 为灰色框创建两个9色块图像。 One for the left side and other for the right side 一个用于左侧,另一个用于右侧
  • For the boxes that must be rendered grey use the appropriate 9-path background (left or right). 对于必须呈灰色显示的框,请使用适当的9路径背景(左或右)。

I implemented it using layer-list. 我使用layer-list实现了它。 Anyone needs to see the code.. Message me. 任何人都需要查看代码。给我发消息。

<!-- Colored rectangle -->
<item>
    <shape android:shape="rectangle" >
        <stroke android:color="@color/color_black" />

        <solid android:color="@color/col_gray_light" />
    </shape>
</item>
<item
    android:bottom="50dp"
    android:left="-25dp"
    android:right="-105dp"
    android:top="-120dp">
    <rotate android:fromDegrees="45" >
        <shape android:shape="rectangle" >
            <solid android:color="@color/color_white" />
        </shape>
    </rotate>
</item>
<item
    android:bottom="63dp"
    android:right="-15dp"
    android:top="-40dp">
    <rotate android:fromDegrees="45" >
        <shape android:shape="rectangle" >
            <solid android:color="@color/color_white" />
        </shape>
    </rotate>
</item>
<item
    android:bottom="-40dp"
    android:right="-20dp"
    android:top="60dp">
    <rotate android:fromDegrees="-45" >
        <shape android:shape="rectangle" >
            <solid android:color="@color/color_white" />
        </shape>
    </rotate>
</item>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM