Android table background color - android

To simulate a grid, I have a tablelayout with background #ffffff, tablerow with background #000000 and textviews with background #dcdcdc.
The entire cell is colored #dcdcdc when the textview has width and height set in fill_parent, but when I add the attribute layout_gravity=center, the width fill_parent attribute is discarded. How can I center the text keeping the whole cell with the expected color?

If i understand correctly...you can use
android:gravity="center"
on the TextView to center the text in the view.

Related

Background color is applied in the whole line

I want the background color (blue) to be applied only where I have letters. Check the image below
Click here to see the example
Not aligned to the right example
Set layout width to wrap content
set TextView width as wrap content, then color will be only in text area

Set Text width more than Display width

I thought that maximum width of a text View in android is display width of the device.I have scroll text that is extended from Linear Layout.By using animation class i can move the text, and its act like a automatic Scrolling text. My problem is the text length(String length 70) exceed the maximum width of the text view (1280 pixel). So the text 70 is show like this (...)
To make a TextView Scrollable the setMovementMethod() has to be called. However, there will be no scroll bar when scrolling it. To add a scroll bar, the android:scrollbars attribute has to be set in the layout file like this:

In a TextView, what's the height of blank between the content text and the border of the TextView?

There will be a blank between the content text and the border of the TextView, even if the padding is 0. And if the height of the TextView and the content text is set to a same value, the text will not be completely displayed.
So, what's the height of blank between the content text and the border of the TextView?
The extra spacing is built into the font. It's there to accomodate special characters that are very tall.
Similar question: How to remove the top and bottom space on textview of Android
Adding android:includeFontPadding="false" may help a little, but I've found it doesn't do much.

Horizontally and Vertically center text for TextView in Android

How do I center the text horizontally and vertically for a TextView in Android?
How do I center the alignment of a TextView?
In Linear Layouts use
android:layout_gravity="center"
In Relative Layouts
android:layout_centerInParent="true"
Above Code will center the textView in layout
To center the text in TextView
android:textAlignment="center"
android:gravity="center"
add this property for textview in xml
textview<android:height="yourheight"
android:width="yourwidth"
android:gravity="center">
your width size should be less than the parent container's width size
It depends on how you have declared the height and width. If you used wrap_content, then the textview is just big enough in that direction to hold the text, so the gravity attribute will not apply. android:gravity affects the location of the text Within the space allocated for the textview. layout_xx attributes affect the location of the view within it's parent.
SO if you set the size of the textview, then use gravity to position the text within the textview area, if you used wrap_content, then use the layout_xx attributes to position the textview within it's parent

How to add Backgroung Image to Tablelayout in Android?

I have TableLayout in my project which contains 6 TableRow layouts. Each TableRow layout has 7 TextViews in it. I want to set a background image to this TableLayout which is currently displaying 42 TextViews. I also had set some background color to each TextView. I tried this
mDateSelectionBar.setBackgroundResource(resid);
But it is not showing up my Image. However, If I do this for my 42 TextViews..
TextView.setBackgroundResource(0);
Then my Image is visible. But I want to display TableLayout background Image as well as background color of each TextView. How can I do this? Please Help! Thanks :D
The issue is that the background of the individual cells in a table layout is drawn over the overall layout background. If you remove the background of the cell, then the overall background is visible. If you need to display the background of the table as well as some colouring of the cells, consider setting the alpha channel of the cell background colour to less than 100%, e.g. 0.8 or something.
When you set the colour for your cells, use #ARGB syntax, e.g.
setBackgroundColour(Color.argb(192, 255, 0, 0));

Categories

Resources