[英]Lager text isn't centred in toolbar
I tried to place the titles of my fragments in centre of the toolbar but one of them is misplaced... I can't figure out why...我试图将片段的标题放在工具栏的中央,但其中一个放错了位置……我不明白为什么……
The code I used is the next one:我使用的代码是下一个:
if (appCompatTextView != null) {
val params: Toolbar.LayoutParams = Toolbar.LayoutParams(Toolbar.LayoutParams.WRAP_CONTENT, Toolbar.LayoutParams.WRAP_CONTENT)
params.gravity = Gravity.CENTER
appCompatTextView.gravity = Gravity.CENTER
appCompatTextView.layoutParams = params
}
The Home
tab toolbar looks like this: “
Home
选项卡工具栏如下所示:
And the Android Studio
tab looks like this: Android Studio
选项卡如下所示:
How should I place the Android Studio
text in center?我应该如何将
Android Studio
文本置于中心位置?
I had similar issue when i try to center it with code.当我尝试将其与代码居中时,我遇到了类似的问题。 So i created an xml file with centered text.
所以我创建了一个文本居中的 xml 文件。 I know it's not what you are searching, but it can get the job done:
我知道这不是您要搜索的内容,但它可以完成工作:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="32sp" />
</LinearLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.