gpt4 book ai didi

android - 工具栏图像居中

转载 作者:IT老高 更新时间:2023-10-28 13:19:48 27 4
gpt4 key购买 nike

使用最后一个 android.support.v7.widget.Toolbar 我想在工具栏中将图像居中,但它一直停留在左侧。

对我来说最好的方法是使用 toolbar.setLogo() 方法并将 Logo 居中,但我没有看到任何方法。

我使用 Toolbar 的布局:

  <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>

是否有可能将图像( Logo )添加到工具栏并将其居中?以编程方式还是在布局中?

最佳答案

Toolbar 只是一个 ViewGroup,你可以随意自定义。

试试这个:

<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 置于工具栏的中心。

关于android - 工具栏图像居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27534343/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com