大佬教程收集整理的这篇文章主要介绍了android – 中心文字垂直独立于视图高度?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我尝试删除填充,边距,改变高度等等.但似乎没有这样做.
即使文字大小接近视图高度,我如何垂直对齐?
以下是包含数字5的视图的代码:
<Button android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="5" android:layout_weight="1" tools:ignore="HardcodedText" android:clickable="false" android:textSize="90dp" android:textColor="?attr/color1" android:gravity="center" android:paddingLeft="@dimen/normal_margin" android:paddingRight="@dimen/normal_margin" android:padding="0dp" />
1.使用GridView
使用gridview,您将在所有四个方向(左,右,上,下)具有相等的空间.您不必担心网格项的相等间距.
<GridView android:id="@+id/album_list" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:cacheColorHint="#00000000" android:gravity="center" android:numColumns="auto_fit" android:stretchMode="spacingWidthUniform" android:drawSelectorOnTop="true"/>
只需尝试以上代码,您将把所有视图均匀分布在网格中.
2.使用TableLayout和TableRow
请检查以下代码以使用TableLayout和TableRow及其属性来平均排列所有视图.即使您更小的TableLayout的高度和宽度,它将保持在该视图中的平均排列.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_margin="5dp"> <TableRow android:weightSum="3" android:layout_weight="1" android:gravity="center"> <Button android:gravity="center" android:textSize="13sp" android:textColor="#000000" android:text="1" android:layout_weight="1"/> <Button android:gravity="center" android:textSize="13sp" android:textColor="#000000" android:text="1" android:layout_weight="1"/> <Button android:gravity="center" android:textSize="13sp" android:textColor="#000000" android:text="1" android:layout_weight="1"/> </TableRow> <TableRow android:weightSum="3" android:layout_weight="1" android:gravity="center"> <Button android:gravity="center" android:textSize="13sp" android:textColor="#000000" android:text="1" android:layout_weight="1"/> <Button android:gravity="center" android:textSize="13sp" android:textColor="#000000" android:text="1" android:layout_weight="1"/> <Button android:gravity="center" android:textSize="13sp" android:textColor="#000000" android:text="1" android:layout_weight="1"/> </TableRow> <TableRow android:weightSum="3" android:layout_weight="1" android:gravity="center"> <Button android:gravity="center" android:textSize="13sp" android:textColor="#000000" android:text="1" android:layout_weight="1"/> <Button android:gravity="center" android:textSize="13sp" android:textColor="#000000" android:text="1" android:layout_weight="1"/> <Button android:gravity="center" android:textSize="13sp" android:textColor="#000000" android:text="1" android:layout_weight="1"/> </TableRow> </TableLayout>
请查找此TableLayout的输出.
让我知道这个问题是否解决了.如果没有,我会很乐意再次帮助你.
享受编码…
以上是大佬教程为你收集整理的android – 中心文字垂直独立于视图高度?全部内容,希望文章能够帮你解决android – 中心文字垂直独立于视图高度?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。