0
我想将公司标志放在ActionBar的中心(绝对屏幕中心)。如何精确计算屏幕的中心点(按宽度)?在屏幕中心的ActionBar上放置图像
活动码:
ActionBar actionBar = getSupportActionBar();
LayoutInflater inflator = (LayoutInflater) this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflator.inflate(R.layout.action_bar_layout, null);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setCustomView(v);
action_bar_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<View
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/common_google_signin_btn_icon_dark_focused"/>
<View
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
有什么想法如何做到这一点?
我意识到现在可能您的意思是如何将图标置于后退按钮和最左侧动作图标的中间? – Joakim
LinearLayout似乎也是如此。问题是将图像放置在屏幕的中心,而不是布局的中心。 – brut
如果你想要的图像在屏幕的中心,它会工作,如果你尝试我建议的工具栏解决方案。 – Joakim