当我把下面的 XML
包含到 layout 文件中时,我可以看到下面的图片。如果你看到了它,你会发现 TextView
有顶部和底部的空间。
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="E1"
android:background="#ff00ff00"/>
我想要去掉这个空格。如何去掉它?这个叫什么? 如果有人知道,请告诉我。谢谢。
当我把下面的 XML
包含到 layout 文件中时,我可以看到下面的图片。如果你看到了它,你会发现 TextView
有顶部和底部的空间。
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="E1"
android:background="#ff00ff00"/>
我想要去掉这个空格。如何去掉它?这个叫什么? 如果有人知道,请告诉我。谢谢。
TopAlignedTextView代码的答案:TopAlignedTextView@GitHub
通过布局使用:
<com.github.captain_miao.view.TopAlignedTextView
android:id="@+id/text_a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:text="@string/text_demo_a"
/>
在LinearLayout中,默认的padding可能会成为一个问题。尝试将其设置为0dp。这对我有用。
我的解决方法相当hacky,但我设法通过将文本视图的高度设置为静态并调整它,直到它刚好适合文本来使文本坐在我想要的位置。在我的情况下,我使用的字体样式的高度为64sp,因此我将我的文本视图的高度设置为50sp,这样就可以正常工作了。我还必须将foreground_gravity设置为底部。
android:includeFontPadding="false"