Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use Shape to make one-sided Block Diagram in Android

Shulou Source: shulou.com Published: 2022-05-31 21:28:39 10月03日 Update

The knowledge of this article "Android how to use Shape to make a single frame" is not understood by most people, so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "Android how to use Shape to make a single frame" article.

The effect is simple:

Take the above figure as an example, only the top frame, the border is red, wide 1dp, and the rest is white.

Idea one

Two layers of canvas superimposed: red at the bottom and white at the top

Move the upper white canvas down to 1dp.

Code implementation:

The left, top, right and bottom attributes of the tag can be understood as the marginXX of view, so it makes sense to follow the second train of thought.

Idea two

Margin has both positive and negative values, so.

Two layers of canvas: the bottom layer is all white; the upper layer has only a red border, and the frame width 1dp

The upper red border sets the left, right and lower margin to-1dp respectively (here, as long as the negative value is greater than the width of the border, and must be greater than the width of the border)

Code implementation:

This is the case with the single border, and by the same token, the two and three borders are simple.

Pick it up on demand.

A pit?

You think it's over when you get to Zili? Pattern Tucson cannon!

Run the code of idea 2 above to see the effect.

What is the situation, the value of width in stroke and the value of left in item are not the same as the ratio of pixels? And the resolution effect of different mobile phones is also different, the higher the resolution, the easier to appear.

Of course, idea two sets the negative absolute value of left in item to be a little larger than that of width; in addition, there is no such problem in idea one.

The above is about the content of this article on "how Android uses Shape to make a single frame". I believe we all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please pay attention to the industry information channel.

Tags: Borders ideas content upper layer white red block diagram production code width effect canvas negative value different resolution only bottom layer article knowledge article Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Shulou Technology Apple NVidia Microsoft