andriod 文本居中: android:gravity="center"
<LinearLayout 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" android:orientation="vertical" android:weightSum="1"> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:layout_marginBottom="10dp"> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="姓:" android:id="@+id/textView" android:layout_weight="1" /> <EditText android:layout_width="0dp" android:layout_height="wrap_content" android:id="@+id/surName" android:layout_weight="4" android:hint="请输入姓氏" android:singleLine="true" /> </LinearLayout> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:layout_marginBottom="10dp"> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="名:" android:id="@+id/textView2" android:layout_weight="1" /> <EditText android:layout_width="0dp" android:layout_height="wrap_content" android:id="@+id/firstName" android:layout_weight="4" android:singleLine="true" android:hint="请输入名字" /> </LinearLayout> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:layout_marginBottom="10dp"> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="电话:" android:id="@+id/textView3" android:layout_weight="1" /> <EditText android:layout_width="0dp" android:layout_height="wrap_content" android:inputType="phone" android:ems="10" android:id="@+id/phone" android:layout_weight="4" android:hint="(02)23963257" /> </LinearLayout> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="确定" android:id="@+id/button" android:onClick="onclick" android:layout_margin="20dp" /> <TextView android:id="@+id/txv" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="我爱你" android:gravity="center" android:textSize="30sp" android:visibility="visible" /> </LinearLayout>
文本居中: android:gravity="center"
也可以在这样
LinearLayout 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" android:orientation="vertical" android:gravity="center"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="变变变..." android:id="@+id/button" android:textSize="45sp" android:onClick="changeColor" /> <TextView android:text="红:?" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/txvR" android:textSize="45sp" /> <TextView android:text="绿:?" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/txvG" android:textSize="45sp" /> <TextView android:text="蓝:?" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/txvB" android:textSize="45sp" /> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="0dp" android:id="@+id/colorBlock" android:layout_weight="1"></LinearLayout> </LinearLayout>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
2016-09-30 arcgis 中删除线,面重复点和删除直线(面)上点的方法
2009-09-30 C# 文本文件批量打印工具
2009-09-30 c#中英文混合字符串截取指定长度