Get / Zigzag for Android / Layout

I need to create a mailing list layout in Android. The idea is very simple: the layout of the rectangle with the bottom edge of the zigzag.

The best result would be a drawable / layout with a fixed zigzag size (which means a fixed size of the polygon), which will multiply the number of triangles according to the actual width of the shape in real time. Perhaps with a clip, if necessary, trim the triangles.

Here is a good example ( edit : I mean the bottom line of the zigzag):

enter image description here

In fact, I have no solid idea of ​​how to create it. Thought of patch 9 but seems unusable. The idea that a list layer can be used with horizontal offsets may be.

It may be possible to create patch 9 with separate sections of the scale to maintain the zigzag aspect ratio ... That would also be nice.

EDIT - ANSWER Using @Luksprog's comment, I easily recreated what I wanted.
Here is the code:

Image (note that the height matches the size of the original image):

<ImageView android:id="@+id/zigzag_bottom" android:layout_width="match_parent" android:layout_height="12dp" android:adjustViewBounds="true" android:scaleType="fitXY" android:src="@drawable/zigzag" /> 

range hood:

  <?xml version="1.0" encoding="utf-8"?> <bitmap xmlns:android="http://schemas.android.com/apk/res/android" android:src="@drawable/ic_zigzag" android:tileMode="repeat" android:antialias="true" /> 
+6
source share
1 answer

You cannot make nine paths for this image because there is no way to define the stretchable area on the vertical or horizontal side. To get this zigzag pattern, you can extract one of the zigzag teeth (along with its background shadow) and wrap it in BitmapDrawable , which has the tileMode property to repeat the wrapped image within the acceptable borders. Thus, the zigzag tooth will be repeated, and you will make a sample.

Note that the height matches the size of the original image

This is a happy scenario, but you can make it work for the case when the height does not match. You can, for example, wrap the zig-zag BitmapDrawable in a LayerDrawable (along with the actual view (for the rest of the viewport)), and then use setLayerInset() to place the picture at the bottom. You can also create your own drawable, which places the zig-zag-image at the bottom, overriding the onDraw () method.

+2
source

Source: https://habr.com/ru/post/976907/


All Articles