如何在工具栏中居中ImageView? [英] How to center ImageView in a toolbar?

查看:144
本文介绍了如何在工具栏中居中ImageView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试将徽标置于工具栏中。当我导航到下一个活动时,会出现up ADVance图标,它会将我的徽标略微向右推。如何在不删除可用性图标的情况下将我的徽标保留在工具栏的中心?

Been trying to center a logo inside my toolbar. When i navigate to the next activity, the "up affordance" icon is present, and it will push my logo slightly to the right. How can I keep my logo at the center of the toolbar, without removing the up affordance icon?

这是我的工具栏标签

<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"

android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/primaryColor"
android:paddingTop="@dimen/app_bar_top_padding"
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark"
app:theme="@style/CustomToolBarTheme">

<ImageView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_android_logo"
    android:layout_gravity="center"
    android:paddingBottom="3dp"/>
 </android.support.v7.widget.Toolbar>


推荐答案

javadoc ,它说:


一个或多个自定义视图。应用程序可能会向工具栏添加任意子
视图。它们将出现在
布局中的这个位置。如果子视图的Toolbar.LayoutParams指示CENTER_HORIZONTAL的Gravity
值,则视图将尝试在所有其他元素已测量
后,在工具栏中剩余的
可用空间中居中

One or more custom views. The application may add arbitrary child views to the Toolbar. They will appear at this position within the layout. If a child view's Toolbar.LayoutParams indicates a Gravity value of CENTER_HORIZONTAL the view will attempt to center within the available space remaining in the Toolbar after all other elements have been measured.

这意味着除非您创建自定义工具栏或删除图标

It means you cannot do it unless you create a custom toolbar or remove the icon.

这篇关于如何在工具栏中居中ImageView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆