我需要水平对齐两个textview
在屏幕中央。两个都textviews
有不同的字体大小。
这是我的代码:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="top|center_horizontal"
android:orientation="horizontal" >
<TextView
android:id="@+id/progressstatus"
android:layout_gravity="center_horizontal"
android:textColor="#FFFFFF"
android:textSize="50sp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/percent"
android:textColor="#CCCCCC"
android:textSize="20sp" />
</LinearLayout>
现在我的文本视图左对齐,并且两者都显示相同的字体大小。
Try It:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal" >
<TextView
android:id="@+id/progressstatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical|right"
android:text="75"
android:textColor="#FFFF00"
android:textSize="50sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:text="%"
android:textColor="#CCCCCC"
android:textSize="20sp" />
</LinearLayout>
说明:我将父级布局设置为wrap_content,意味着父级将根据子级高度包裹其高度。父级中有 2 个文本视图。一种字体较大,另一种字体较小。较大的字体大小视图肯定会比较小的字体具有更高的高度。所以,我为wrap_content设置了更大的高度。现在,较小的视图的高度是 match_parent,意味着较小的视图将自身扩展到父级的最大高度,该高度等于较大字体的视图的高度。因此,两者都将居中对齐。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)