Android table with round border
Asked Answered
D

3

26

How can I make a table with a round border, similar to the photo below, in Android?

Round-bordered table

Dietrich answered 5/3, 2010 at 13:33 Comment(0)
A
55

I think Androidbase linked to the wrong question... he asked a similar question recently, and here's the answer I gave him:

You can put a coloured background with rounded corners into a table by using a Shape background. Create such a shape in an XML file, put in your drawables folder.

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#99FFFFFF"/>
    <corners android:radius="30px"/>
    <padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" /> 
</shape>

For example the above creates a semi-transparent white background with 30px rounded corners. You set this to the table by using

android:background="@drawable/my_shape_file"

in the XML file where you defined your table layout.

Agrobiology answered 5/3, 2010 at 15:18 Comment(2)
can any suggest me how to remove rounded corner of button ... thnxNadda
+1. this was awesome. also, if you want to set it on your table row programatically instead (say if you're alternating background shapes) use: tableRow.setBackgroundResource(R.drawable.my_shape_file); more info hereViaticum
E
0

I prefer to use a masking technique - overlay a mask image (any iOS-style background, with a transparent cutout in it) over a standard layout.

This way, the background of my layout is not linked directly to a bitmap, I can change it very easily.

I have an answer explaining that here: Android XML rounded clipped corners

Esau answered 30/11, 2011 at 9:6 Comment(0)
B
0

I had a similar task recently so I decided to write a library for this purpose. Feel free to use it for your needs... https://github.com/vladexologija/GroupedTextView

GroupedTextView

Boden answered 13/3, 2012 at 9:21 Comment(2)
But it doesn't horizontally align the text on the right with your current implementation, right? It seems like a TableView will be better to use for implementation.Antoniettaantonin
It's all there on Github, change it to android:gravity="right" if you prefer right alignment.Boden

© 2022 - 2024 — McMap. All rights reserved.