Android: how to set background image in table layout

I need to use tablelayout to display elements from sqlite db. I set the inverse image for the table layout, but the image appears below the texts that I need to display the image back into texts, and not below, i.e. I need an image frame as 0.0 What do I need to do. Now i used

.setbackgroundresources(r.drawable.imagename) 

I ask you, I need to add background images for the table layout programmatically

+4
source share
2 answers

If you set a background resource for the layout, and the image appears under the layout itself (i.e., below all the components), you probably are not adding the background resource to the correct layout.

But since you do not have much information, this may not even be so.

Maybe your image is actually much smaller than the table itself, and instead of expanding to the size of the table, can it stay at a fixed level (which would probably be centered in the layout)?

Try setting the table background to a fixed color (i.e. view.setBackgroundColor (Color.BLACK);) to check this. If the whole table is populated as you expected, it is probably related to the image you are using.

If the color fills only the same area that the image resource used previously, then this is probably my first thought that you are not adding the resource to the corresponding layout.

+2
source

then try putting one external layout of the linear layout of the table layout in your .xml file, and then set the background of this linear layout, for example

 <LinearLayout android:id="@+id/linearLayout1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/bkg1"> <TableLayout android:id="@+id/linearLayout1_tblLayout1" android:layout_width="wrap_content" android:layout_height="wrap_content" > <TableRow android:id="@+id/linearLayout1_tblLayout1_tableRow1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" > ...... </TableRow> </TableLayout> </LinearLayout> 
0
source

Source: https://habr.com/ru/post/1414362/


All Articles