In this series I’m going to talk about APIs of Android, that most of developers, despite being quite experienced with Android SDK, do not know about their existence.
In part 1 we examined
<blink> tag. In this episode we are going to dive into a feature of
LinearLayout , that I have never seen anybody using.
Imagine a simple horizontal
LinearLayout , wherein 5 fancy squares are shown:
Now the requirement is to introduce a divider between these 5 views like this:
How would you solve the problem?
Would you introduce a new divider view between each of these squares?
<LinearLayout ...> <View .../>
Sure, this would solve the problem. But turns out that
LinearLayout internally possesses such a feature. Please welcome
android:divider is not yet necessary -
android:showDividers should also be set, otherwise it defaults to
none . There are four options in total:
As you have already guessed,
end would apply divider only to beginning and and respectively.
U̶n̶f̶o̶r̶t̶u̶n̶a̶t̶e̶l̶y̶,̶ ̶t̶h̶e̶r̶e̶ ̶d̶o̶e̶s̶ ̶n̶o̶t̶ ̶e̶x̶i̶s̶t̶ ̶a̶ ̶w̶a̶y̶ ̶t̶o̶ ̶a̶p̶p̶l̶y̶ ̶d̶i̶v̶i̶d̶e̶r̶ ̶f̶o̶r̶ ̶b̶e̶g̶i̶n̶n̶i̶n̶g̶,̶ ̶m̶i̶d̶d̶l̶e̶ ̶a̶n̶d̶ ̶e̶n̶d̶ ̶s̶i̶m̶u̶l̶t̶a̶n̶e̶o̶u̶s̶l̶y̶,̶ ̶w̶h̶i̶c̶h̶ ̶i̶s̶ ̶a̶ ̶b̶i̶t̶ ̶w̶e̶i̶r̶d̶.̶ ̶
As pointed out by Aris Papadopoulos 👏, you can apply dividers for both beginning, middle and end just by bitwise OR-ing the flags:
Happy droiding! 🤖