在线性布局下垂直方向 如何实现textview垂直水平居中

在线性布局下垂直方向 如何实现textview垂直水平居中


用center的方法任然只能水平居中

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:orientation="horizontal" >


    <TextView

        android:layout_width="100dp"

        android:layout_height="50dp"

        android:background="#ff00ff"

        android:gravity="center"

        android:text="top"

        android:layout_gravity="center_vertical|center_horizontal" />


</LinearLayout>


正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

2回答
提问者 liquid123 2018-10-23 17:43:35

谢谢老师 学习了

irista23 2018-10-23 13:40:52

当LinearLayout设置android:orientation="horizontal" 时, 只有垂直方向的top,bottom,center_vertical设置才起作用,水平方向的设置不起作用。如果想让子元素垂直水平居中,可以为线性布局添加android:gravity="center"属性设置。

问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师