android - 如何在注销图标之前的右侧边缘(即)显示 ImageView ?

标签 android android-actionbar imageview action

我想在注销图标之前在操作栏上显示个人资料图片,但它在应用程序标题之后显示图像。我已经使用 Image View 和 Picasso 来使用 volley 从服务器加载图像。如何实现这一目标?

actionBar.setDisplayOptions(actionBar.getDisplayOptions()
                            | ActionBar.DISPLAY_SHOW_CUSTOM);

                    imageView.setScaleType(ImageView.ScaleType.CENTER);
                    Picasso.with(HomeActivity.this).load(AppConfig.profilePic + image).placeholder(R.drawable.profile).transform(new CircleTransform()).fit().into(imageView);
                    ActionBar.LayoutParams layoutParams = new ActionBar.LayoutParams(
                            ActionBar.LayoutParams.WRAP_CONTENT,
                            ActionBar.LayoutParams.WRAP_CONTENT, Gravity.RIGHT
                            | Gravity.CENTER_VERTICAL);
                    layoutParams.gravity = Gravity.RIGHT;
                    imageView.setLayoutParams(layoutParams);
                    actionBar.setCustomView(imageView);

enter image description here

最佳答案

这不能在那里完成,因为它的标准是首先显示标题 解决方案 >> 使用自定义操作栏 1-建立自己的布局 2- 在样式文件中将您的应用程序的主题更改为 NoAction 栏 3- 使用 include 将您的自定义 actionBar 添加到您想要的任何布局

<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    app:layout_scrollFlags="scroll|enterAlways"
    app:layout_collapseMode="pin">
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ImageView
            android:id="@+id/toolbar_logo"
            android:src="@drawable/logo"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_marginRight="?attr/actionBarSize"
            android:layout_marginTop="4dp"
            android:layout_marginBottom="4dp" />

        <TextView
            android:id="@+id/toolbar_title"
            android:orientation="horizontal"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_marginRight="?attr/actionBarSize"
            android:layout_gravity="center"
            android:gravity="center_vertical"
            android:visibility="gone"
            android:text="@string/app_name"
            android:textColor="@color/white"
            style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title.Inverse"
            />


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

关于android - 如何在注销图标之前的右侧边缘(即)显示 ImageView ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45706494/

相关文章:

android - 当两行文本时按钮改变位置

android - 如何删除饼图中的底部空间?

android - 我可以在 Monodroid 中使用什么来替代 Action Bar?

java - 在什么情况下我可以使用选项菜单/操作栏项调用 findViewById?

Android ScrollView 在子 ImageView 的顶部和底部添加了额外的填充

android - 如何在android放大后画一个圆圈

android - 如何通过触摸中断长时间的处理?

android - 进入 IOEx catch block 时蓝牙套接字变为空(android 4)

android - Robolectric:actionBar.hide() 返回 Null

android - ImageView 中未显示相机文件夹图像