2015-10-20 55 views
3

我試圖用導航按鈕和工具欄的標題分別對齊圖標和文本字段。如何與工具欄的標題對齊?

根據設計規範,標題是72dp從左側邊緣走:

enter image description here

如果我使用72dp,像下面,我沒有得到一個對準

<?xml version="1.0" encoding="utf-8"?> 
<merge xmlns:android="http://schemas.android.com/apk/res/android"> 
    <ImageView android:layout_width="56dp" 
       android:layout_height="56dp" 
       android:padding="16dp" 
       android:id="@+id/icon"/> 

    <EditText android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:singleLine="true" 
       android:id="@+id/text" 
       android:layout_marginLeft="16dp" 
       android:layout_marginRight="16dp"/> 
</merge> 

enter image description here

有誰知道什麼可能是錯的?

感謝

UPDATE定製工具欄按@麥克的建議是:

enter image description here

enter image description here

+0

您的添加填充到您的ImageView,這是拋出對齊以及...啓用在您的開發人員設置中繪製佈局邊界太多,這將幫助您看到您的imageView邊界正在移動 –

回答

1

首先要提的是,在您粘貼的截圖標題是不是在72dp從左邊,但它看起來像56dp。

基本上問題是谷歌在他們的文檔中寫了一些東西,但是當涉及到實現的東西時,他們會以不同的方式做。

Here是一個非常棒的帖子,從Lucas Urbas詳細解釋了Android上的所有工具欄誤解。

+0

你知道爲什麼這可能是如果規格狀態爲72dp?仿真器在Nexus 4上使用API​​ 22. – Kar

+0

這基本上是因爲Google在其文檔中寫入了一些內容,並且在實現某些功能時他們還做了其他事情:)。我會用一篇偉大的文章編輯我的答案,你應該考慮閱讀以澄清一切。 – Mike

+0

謝謝。我正在嘗試解決方案,但是你知道'@ style/Toolbar.AppCompat.Responsive'和'@ style/Toolbar.Popup.AppCompat'這些主題是從哪裏來的嗎? – Kar