如何將工具欄中的圖標與中間對齊?我已經刪除了標籤getSupportActionBar().setDisplayShowTitleEnabled(false);
爲我的工具欄創建一個xml文件是最好的主意嗎?對齊工具欄中的圖標
0
A
回答
1
是在工具欄中創建一些佈局,並在佈局中可以有其他控件(視圖)。
工具欄與其他佈局類似,可以嵌套它們。 。
mToolbar.getViewTreeObserver()addOnGlobalLayoutListener(新ViewTreeObserver.OnGlobalLayoutListener(){ @覆蓋 公共無效onGlobalLayout(){ ImageView的ImageView的=(ImageView的:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_actionbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:text="@string/news"/>
</RelativeLayout>
</Toolbar>
1
編程,你可以如下做到這一點)mToolbar.findViewById(R.id.logo); 如果(mToolbar == NULL){ 回報; } INT toolbarWidth = mToolbar.getWidth(); INT imageWidth = imageView.getWidth(); imageView.setX((toolbarWidth-imageWidth)/ 2); } }); 定製您的layout_toolbar.xml:
<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"
style="@style/Toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height"
android:background="@drawable/toolbar_background"
android:focusable="false"
app:titleTextAppearance="@style/AppTheme.Toolbar.Title">
<ImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/toolbar_logo"/>
</android.support.v7.widget.Toolbar>
相關問題
- 1. 將Eclipse工具欄圖標左對齊
- 2. 將圖標與工具欄圖標對齊 - Android Material Design
- 3. 工具欄中的標題圖像對齊方式android
- 4. Android的導航工具欄圖標和標識不能對齊
- 5. 右上對齊的MFC工具欄對齊
- 6. 自定義工具欄佈局對齊
- 7. 通過代碼左對齊工具欄
- 8. 黑莓UI工具欄:字段對齊
- 9. Ios ::工具欄對齊問題
- 10. 工具欄標題的項目對齊問題?
- 11. 如何與工具欄的標題對齊?
- 12. Android的工具欄菜單圖標和文本沒有正確對齊
- 13. 將SearchView提示與工具欄標題展開後對齊
- 14. 操作欄(工具欄)圖標
- 15. 在gtk工具欄中排列圖標
- 16. 工具欄圖標不居中
- 17. 從AppCompat繼承工具欄更改工具欄圖標邊距
- 18. Eclipse RCP:工具欄中的右對齊搜索字段
- 19. 用圖標替換工具欄標題
- 20. 工具欄圖標的不全白
- 21. Android的工具欄圖標定位
- 22. BlackBerry應用程序中的工具欄或圖標欄
- 23. 工具欄在發佈版本中未對齊
- 24. 如何在Quill工具欄中添加對齊按鈕?
- 25. 如何正確對齊Java SWT統一工具欄中的搜索欄(OS X)
- 26. 所有視圖中的工具欄(全局工具欄)
- 27. AChartEngine條形圖欄對齊
- 28. 標籤內的工具欄
- 29. 將工具欄標題和SearchView與包含頭像的列表內容對齊
- 30. Xamarin.Forms工具欄項目圖標大小