zoukankan      html  css  js  c++  java
  • Android UI 如何让TextView中的文字居中显示

    在我们平时做开发的过程中,总是会有布局要考虑,不光是大布局,像LinearLayout这样,小的如文字在View中的布局也影响到整体的美观,所以,在开发中要多多留意这些细节部分的布局,在Android中,文字居中很多人都不知道在哪里。包括很多Web开发人员也是,总以为是一个叫align的属性。我也不例外,不过借助百度搜索,我找到了解决方案,就把它存起来吧。以后可能又会忘记的。

    页面布局是LinearLayout里包一个TextView控件

    1.方法一:TextView设置android:gravity=”center”,同时TextView设置android:layout_width=”fill_parent”
    举例代码:

    <LinearLayout android:orientation=”horizontal”    
    android:layout_width=”fill_parent” android:layout_height=”40sp”    
    android:background=”@drawable/top_businesscard_1″>   
    <TextView android:layout_width=”fill_parent” android:gravity=”center”    
    android:textColor=”#447324″ android:textSize=”18dp” android:text=”@string/logo_text”    
    android:layout_height=”wrap_content” android:layout_marginTop=”10dp”/>   
    </LinearLayout>   

    方法二:LinearLayout设置android:gravity=”center_horizontal”,同时TextView设置android:layout_width=”wrap_content”
    举例代码:

    <LinearLayout android:orientation=“horizontal”   
    android:layout_width=“fill_parent” android:layout_height=“40sp”   
    android:background=“@drawable/top_businesscard_1″ android:gravity=“center_horizontal”>   
    <TextView android:layout_width=“wrap_content”   
    android:textColor=“#447324″ android:textSize=“18dp” android:text=“@string/logo_text”   
    android:layout_height=“wrap_content” android:layout_marginTop=“10dp”/>   
    </LinearLayout>   
  • 相关阅读:
    漏洞都是怎么编号的CVE/CAN/BUGTRAQ/CNCVE/CNVD/CNNVD
    数据集成之主数据管理(一)基础概念篇
    hdu 4940 Destroy Transportation system(水过)
    关于C++ const 的全面总结
    UserManageSys
    malloc函数具体解释
    Haskell 差点儿无痛苦上手指南
    机房收费系统——附加数据库
    面向对象程序设计与面向过程程序设计解析
    java的System.getProperty()方法能够获取的值
  • 原文地址:https://www.cnblogs.com/xuewater/p/2624048.html
Copyright © 2011-2022 走看看