android – 中心文字垂直独立于视图高度?

android – 中心文字垂直独立于视图高度?,第1张

概述我正在尽最大努力让文本垂直居中,但我无法做到这一点.问题是我有一些按钮的height = fill_parent和weight = 1,随着行变小我的文本开始触摸视图的底部,如下所示: 我尝试删除填充,边距,改变高度等等.但似乎没有这样做. 即使文字大小接近视图高度,我如何垂直对齐? 以下是包含数字5的视图的代码: <Button android:layout_width="fil 我正在尽最大努力让文本垂直居中,但我无法做到这一点.问题是我有一些按钮的height = fill_parent和weight = 1,随着行变小我的文本开始触摸视图的底部,如下所示:

我尝试删除填充,边距,改变高度等等.但似乎没有这样做.

即使文字大小接近视图高度,我如何垂直对齐?

以下是包含数字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" />
解决方法 根据我的建议,如果你有两个选项,从你的问题做这样的布局和getout.

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 – 中心文字垂直独立于视图高度?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1131827.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存