[Turn]android use shape stroke strokes to retain only the bottom

Source: Internet
Author: User

This situation is encountered in the project: For some reason, you need to use the vertical layout of the LinearLayout to make the ListView effect, but the ListView comes with a split line, and the bottom of the top is no split line, each item in the middle is a 1dp width of the split line. I started with the idea that each item in LinearLayout had a background set with a shape file, so I wrote the following shape:

<shape xmlns:android= "Http://schemas.android.com/apk/res/android" >    <stroke        android:color= "# B4b4b4 "        android:width=" 1DP "/>    <solid        android:color=" @android: Color/transparent "/></ Shape>

But look at this shape, it is estimated that everyone can imagine the effect is not correct, because the last item has a 1DP bottom, the next item also has a 1DP bottom, so that the partition between the item has 2DP, it is difficult to see, is not the effect we want. As shown in the effect:

So the question to be solved is how to keep only the bottom of the stroke. After some modification experiments, using layer-list can solve this problem, very simple, as shown in the following code:

<layer-list xmlns:android= "Http://schemas.android.com/apk/res/android" >    <item        android:top= "- 2DP "        android:right=" -2DP "        android:left=" -2DP ">        <shape>            <solid android:color=" @ Android:color/transparent "/>            <stroke                android:width=" 1DP "                android:color=" #B4B4B4 "/>        </shape>    </item></layer-list>

The key is to look at the properties of the <item> tag, set top, right and left to -2DP, and the shape stroke width is only 1dp, so that the left-hand line is gone, only the bottom edge will be preserved. (may be asked why not the top, right, left set to -1DP, I have tried, it seems to be a stroke, the automatic will be in the outside of the stroke more than 1DP margin, look closely can be seen, So there's more than 1DP to completely remove the stroke on the opposite side. You can try it yourself.)

The final effect looks like this:

The last item of the background is not set on OK, the actual performance is exactly the same! That's it!

[Turn]android use shape stroke strokes to retain only the bottom

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.