Ever wanted to have a LinearLayout to auto span through the screen, more over take the whole screen width and expand itself with equal spaces in between the elements ? Well I know have.😉
So here’s another short and sweet code sharing post!😀
So what happened ?
Well anyhow usually during such above scenarios the first thing that come’s to my mind is the RelativeLayout in Android, so I went ahead and implemented it, whereas I had two buttons in the corner and a textview in the middle, I just needed it to be auto spanned the whole screen width and take equal space in between. I managed to create the design as expected but weirdly enough, the click events of the buttons weren’t working, and literally the I wasn’t able to click on the buttons, as if RelativeLayout was hovering over the buttons.
Oh yes I tried enabling the Clickable property of RelativeLayout as well, even the Focus enable property, but nothing worked!
LinearLayout for the rescue!
So helplessly I forced myself to change to LinearLayout, and lucky enough I managed to get it done after a few hours of playing around lol! :D It still doesn’t make any sense why the buttons weren’t clickable inside the RelativeLayout. However I’m glad I figured out a workaround with the LinearLayout.
So anyways if any of you run into such situation, or looking to implement LinearLayout for a similar situation, here is the code XML code I used for my layout.😉
So basically what I have done is, added empty LinearLayouts in between the buttons and assign an equal weight to the layout property. This will make the layout span across the full screen width, taking equal spaces in between, despite of Landscape mode Portrait mode. You could even assign different spacing in between the buttons, which will get automatically maintained among Landscape and Portrait modes.🙂
Here’s how it actually looks like…
WOOT! WOOT!😀 there you go !😉 Enjoy!
Stay Awesome fellas!