工具栏图像居中 [英] Toolbar image centered

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

问题描述

使用最后android.support.v7.widget.Toolbar我想中心的图像的工具栏,但它继续位于在左侧。 对我来说,最好的办法是使用toolbar.setLogo()方法,并居中标志,但我看不出有什么办法做到这一点。

Using the last android.support.v7.widget.Toolbar I want to center an image in the toolbar but it keeps staying on the left. The best way for me would be to use toolbar.setLogo() method and to center the logo but i don't see any way to do it.

我用的布局工具栏:

  <android.support.v7.widget.Toolbar style="@style/ToolBarStyle"
                                   xmlns:android="http://schemas.android.com/apk/res/android"
                                   android:layout_width="match_parent"
                                   android:layout_height="wrap_content"
                                   android:background="?attr/colorPrimary"
                                   android:minHeight="@dimen/abc_action_bar_default_height_material">

</android.support.v7.widget.Toolbar>

是否有可能将图像(徽标)添加到工具栏和中心呢? 编程或在布局?

Is there any possibility to add an image (logo) to the toolbar and center it ? programatically or in the layout ?

推荐答案

工具栏只是一个ViewGroup中,你可以自定义的,只要你想尽可能多的。

Toolbar is just a ViewGroup, you can customize is as much as you want.

试试这个:

<android.support.v7.widget.Toolbar
   style="@style/ToolBarStyle"
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:background="?attr/colorPrimary"
   android:minHeight="@dimen/abc_action_bar_default_height_material">

    <ImageView
        android:layout_width="wrap_content"
        android:contentDescription="@string/logo"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:src="@drawable/ic_launcher"/>

 </android.support.v7.widget.Toolbar>

本应带来的工具栏中心的ImageView的。

This should bring your imageView in center of toolbar.

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

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