Android: ExpandableListActivity Icons Overlapping Text

I am trying to create a very simple ExpandableListActivity based on the Demos API Code example :

The default layout appears broken, as the expand / collapse icons overlap the list item text.

Unfortunately, even though the demo just uses the default layout, the layout does not look like that. It seems that the text does not have enough indentation, so the expand / collapse icons overlap the text of the list item, as the screenshot demonstrates.

Why is this happening and how can I fix it?

Thanks!

+4
source share
1 answer

The problem is the getGenericTextView() method of the getGenericTextView() code:

 // Set the text starting position textView.setPadding(36, 0, 0, 0); 

setPadding(...) sets the registration (internal space) in pixels, which means that the result of this indentation will be different for each device. It seems you are using an hdpi device with a relatively large horizontal screen resolution, resulting in visually too little space on the left side of the TextView. For a more detailed explanation of this problem, read here.

Thus, you can easily overcome the problem by setting the pixel density (d (i) p) so that the space with visual indentation is the same in different resolutions. You can use TypedValue for this:

 int dips = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 36, getResources().getDisplayMetrics()); 

Alternatively, you can inflate a TextView from xml, on which you can set density-independent properties at design time, rather than doing it on the fly at run time.

+6
source

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


All Articles