android– 为什么标题不在工具栏中居中?

android– 为什么标题不在工具栏中居中?,第1张

概述我想添加自定义工具栏我想要购物车徽章计数所以我添加相对布局到工具栏小部件,当我没有在工具栏中添加相对布局标题出现在中心但现在删除相对布局导致问题添加徽章textview在购物车上,有谁能建议在这种情况下做什么?Toolbar.xml    <android.support.v7.widget.Toolbarxmlns

我想添加自定义工具栏我想要购物车徽章计数所以我添加相对布局到工具栏小部件,当我没有在工具栏中添加相对布局标题出现在中心但现在删除相对布局导致问题添加徽章textvIEw在购物车上,有谁能建议在这种情况下做什么?
Toolbar.xml
    

<androID.support.v7.Widget.Toolbarxmlns: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:ID="@+ID/mytoolbar"androID:layout_wIDth="match_parent"androID:layout_height="wrap_content"app:contentInsetStart="0dp"app:contentInsetRight="0dp"app:contentInsetleft="0dp"androID:clipTopadding="false"app:contentInsetStartWithNavigation="0dp"app:contentInsetEnDWithActions="0dp"androID:background="@color/header"><relativeLayout    androID:layout_wIDth="match_parent"    androID:layout_height="wrap_content"><TextVIEw    androID:ID="@+ID/displaytexttoolbar"    androID:layout_wIDth="wrap_content"    androID:layout_height="wrap_content"    androID:layout_centerInParent="true"    androID:layout_gravity="center"    androID:layout_margin="@dimen/activity_vertical_margin"    androID:text="TEXT_VIEW"    androID:textcolor="@color/white" /><relativeLayout    androID:layout_gravity="right"    androID:layout_wIDth="wrap_content"    androID:layout_height="wrap_content">    <ImageVIEw        androID:ID="@+ID/cart_imagetoolbar"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_alignParentRight="true"        androID:layout_centerVertical="true"        androID:layout_gravity="end"        androID:layout_margin="@dimen/activity_vertical_margin"        androID:src="@drawable/cart_mobile_white" />    <TextVIEw        androID:ID="@+ID/tvBadge"        androID:layout_wIDth="20dp"        androID:layout_height="20dp"        androID:layout_alignParentRight="true"        androID:layout_gravity="right"        androID:background="@drawable/cart_circle_mobile"        androID:gravity="center"        androID:textcolor="@color/white"        androID:visibility="visible" /></relativeLayout></relativeLayout>


解决方法:

它与你的layout_margin有关.试试以下内容:

<TextVIEw    androID:ID="@+ID/displaytexttoolbar"    androID:layout_wIDth="wrap_content"    androID:layout_height="wrap_content"    androID:layout_gravity="center"    androID:layout_marginleft|Right="?attr/actionbarSize"    androID:text="TEXT_VIEW"    androID:textcolor="@color/white" />
总结

以上是内存溢出为你收集整理的android – 为什么标题不在工具栏中居中?全部内容,希望文章能够帮你解决android – 为什么标题不在工具栏中居中?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1115177.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存