简体   繁体   English

TextView Top Padding问题?

[英]TextView Top Padding Issue?

Padding issue? 填充问题?

Update Sample of the issue:- 更新问题样本: -

示例gridview单元格的问题

(Why is there a gap above the word "Late") (为什么“Late”这个词之上有差距)

Update 2 Others gave reported similar issues here:- http://code.google.com/p/android/issues/detail?id=22493 更新2其他人在此处报告了类似问题: - 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. 所以看起来textview一旦变大就不会缩小尺寸。 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中以形成日历: -

<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. 用于使用项目填充gridview的适配器会更改@ + id / DateCode的文本大小,以使文本适合可用空间的宽度。 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). 然后它会使textview无效并强制重新布局(我知道这有效,因为textview的底部确实出现在调整大小的文本的底部)。

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. DateCode中文本的顶部似乎至少在TextView的一半处开始(这是一个明显的红色框。我不明白为什么该区域没有缩小以适应文本。

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? 任何想法为什么textview将文本定位到目前为止,而不是将它包装到一个小得多的空间?

  • Anthony 安东尼

If you are using ADT in Eclipse, then use the Hierarchy Viewer perspective to inspect live Views. 如果在Eclipse中使用ADT,则使用“层次结构查看器”透视图检查实时视图。 That way you can know for sure what is going on with the layout; 这样你就可以确定布局发生了什么; but to me the two TextViews look suspicious (ie where is the other? is it empty?) 但对我来说,两个TextView看起来很可疑(即另一个是哪里?它是空的吗?)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM