Thursday, July 10, 2014

How to implement a dynamic dotted line around a view android

Hi there!

Today i'm gonna share a cool think with you. A way to implement a dotted line that grows dynamically around a view. I tryed to resolve it using a nine patch (.9.png) but without success. The end result will look like this:


Resource definition

Define a resource called dotted_pattern.xml in the folder drawable

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
        <shape>
            <stroke
                android:dashGap="6dp"
                android:dashWidth="6dp"
                android:width="3dp"
                android:color="#ec9a87" />
        </shape>
    </item>
</layer-list>


Layout definition (your view)

Create in your layout a view like this. Set the defined resource like shown bellow

<FrameLayout
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:layout_gravity="center"
 android:background="@drawable/dotted_pattern"
android:layerType="hardware" /> 


That's all. hope you like it.

😱👇 PROMOTIONAL DISCOUNT: BOOKS AND IPODS PRO ðŸ˜±ðŸ‘‡

Be sure to read, it will change your life!
Show your work by Austin Kleonhttps://amzn.to/34NVmwx

This book is a must read - it will put you in another level! (Expert)
Agile Software Development, Principles, Patterns, and Practiceshttps://amzn.to/30WQSm2

Write cleaner code and stand out!
Clean Code - A Handbook of Agile Software Craftsmanship: https://amzn.to/33RvaSv

This book is very practical, straightforward and to the point! Worth every penny!
Kotlin for Android App Development (Developer's Library): https://amzn.to/33VZ6gp

Needless to say, these are top right?
Apple AirPods Pro: https://amzn.to/2GOICxy

😱👆 PROMOTIONAL DISCOUNT: BOOKS AND IPODS PRO ðŸ˜±ðŸ‘†