5

Padding issue?

Update Sample of the issue:-

sample gridview cell with the issue

(Why is there a gap above the word "Late")

Update 2 Others gave reported similar issues here:- http://code.google.com/p/android/issues/detail?id=22493

So it seems that a textview doesn't reduce in size once it's been bigger. Any ideas for workarounds for this? setting the height explicitly causes the text to be cropped as it's lower than it should be.


I have a layout as follows:-

  <?xml version="1.0" encoding="utf-8" ?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="1dp"
    android:orientation="vertical"
    android:background="@color/Green">
  <TextView 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/datetext" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="14sp" 
    android:textStyle="bold" /> 
  <TextView 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/DateCode" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="40sp"
    android:textStyle="bold"
    android:background="@color/Red" /> 
  </LinearLayout>

and it is populated into a this GridView to form a calendar:-

<GridView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/gridview"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:numColumns="7"
    android:verticalSpacing="2dp"
    android:horizontalSpacing="2dp"
    android:stretchMode="columnWidth"
    android:gravity="center"
/>

The adapter used to populate the gridview with the items changes the text size of @+id/DateCode to fit the text to the width of the available space. it then invalidates the textview and forces a re-layout (I know this works as the bottom of the textview does come up to the bottom of the resized text).

The top of the text within DateCode seems to start at least halfway down the TextView (which is clear as a red box. I don't understand why the area is not shrunk to fit the text in.

I assume it's a padding issue or something I don't understand, but it doesn't seem to be the font padding given how big it is.

Any ideas why the textview is positioning the text so far down, and not wrapping it into a much smaller space?

  • Anthony
Anthony Graham
  • 451
  • 4
  • 13

1 Answers1

0

If you are using ADT in Eclipse, then use the Hierarchy Viewer perspective to inspect live Views. That way you can know for sure what is going on with the layout; but to me the two TextViews look suspicious (i.e. where is the other? is it empty?)

P Varga
  • 19,174
  • 12
  • 70
  • 108
  • I'm downloading the emulators now, my phone doesn't have the required android build for UI debugging so I can try that. the first textview says "1" and is above the other one in the screenshot :) – Anthony Graham Mar 01 '12 at 21:50
  • that doesn't seem to reveal anything, I explored it and nothing seemed out of place. – Anthony Graham Mar 02 '12 at 08:27
  • Weird. And sorry, I'm colorblind so the screenshot seemed a bit cryptic. I have never seen this behavior though... Is it the same if the text is just one letter instead? – P Varga Mar 02 '12 at 12:29
  • 1
    I think it's a bug, others have experienced it too aparently, http://code.google.com/p/android/issues/detail?id=22493 the work arounds there I'm not comfortable using unless I understand the bug / why the workaround works. – Anthony Graham Mar 02 '12 at 13:01