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