2015-01-08 126 views
1

所以我試圖按照lists上的Google新Material Design guidelines。但我看不出我應該得到的結果。這是它應該是這樣的:材料設計列表指南Android 5.0

Google example of list with material design guidelines

這是我的名單看起來像codewise:

<ImageView 
    android:id="@+id/contact_item_image" 
    android:background="@android:color/black" 
    android:layout_width="40dp" 
    android:layout_height="40dp" 
    android:layout_marginLeft="@dimen/left_margin" 
    android:layout_centerVertical="true"/> 

<View 
    android:id="@+id/middle_splitter" 
    android:layout_width="match_parent" 
    android:layout_height="1px" 
    android:layout_centerVertical="true"/> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingLeft="72dp" 
    android:paddingTop="20dp" 
    android:paddingBottom="20dp" 
    android:paddingRight="@dimen/right_margin" 
    android:orientation="vertical"> 

    <TextView 
     android:id="@+id/contact_item_prim_text" 
     android:text="Test title" 
     android:textSize="@dimen/subhead_txt_size" 
     android:textColor="@color/blackish" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     /> 

    <TextView 
     android:id="@+id/contact_item_sec_text" 
     android:text="Test sec title" 
     android:textSize="@dimen/body1_txt_size" 
     android:textColor="@color/android_greyish" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     /> 
</LinearLayout> 

沒有的LinearLayout還tryed:

<ImageView 
    android:id="@+id/contact_item_image" 
    android:background="@android:color/black" 
    android:layout_width="40dp" 
    android:layout_height="40dp" 
    android:layout_marginLeft="@dimen/left_margin" 
    android:layout_centerVertical="true"/> 

<View 
    android:id="@+id/middle_splitter" 
    android:layout_width="match_parent" 
    android:layout_height="1px" 
    android:layout_centerVertical="true"/> 

<TextView 
    android:id="@+id/contact_item_prim_text" 
    android:text="Test title" 
    android:textSize="@dimen/subhead_txt_size" 
    android:textColor="@color/blackish" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:paddingLeft="72dp" 
    android:paddingTop="20dp" 
    android:paddingRight="@dimen/right_margin" 
    android:layout_above="@id/middle_splitter" 
    /> 

<TextView 
    android:id="@+id/contact_item_sec_text" 
    android:text="Test sec title" 
    android:textSize="@dimen/body1_txt_size" 
    android:textColor="@color/android_greyish" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:paddingLeft="72dp" 
    android:paddingBottom="20dp" 
    android:paddingRight="@dimen/right_margin" 
    android:layout_below="@id/middle_splitter" 
    /> 

但實際的結果是更多這樣的:

Device picture of personal list implementation

我基本上只是輸入的尺寸直接爲材料設計網站上的規定,但它看起來並不正確,很我誤解了這些指南或什麼?設計本身可以輕鬆地通過讓LinearLayout使用權重或使用RelativeLayout定位來處理,我只是儘管這些指導原則應該幫助我們完成......關於我們應該如何使用這些指南的任何想法或他們只對設計師而不是開發者?

編輯

所以,我提出了一個答案的可能解決方案。仍然認爲一些代碼示例來自Google的部分非常棒。

+0

請勿在TextView中使用paddingTop和paddingBottom。每種字體都在字符的上下有一些空格,TextView使用它們。只需設置重力=「center_vertical」和layout_height =「match_parent」 – Zielony

+0

@Zielony葉我知道,我只是想嘗試遵循他們的指導方針,看看我能否得到正確的結果。如果你去到網站,你會看到他們指定設置給定區域的填充。 – Warpzit

+0

只要遇到這個確切的問題,如果我們不應該使用頂部和底部填充,他們爲什麼包括在內呢?該文檔對這兩個值沒有意義 –

回答

0

所以我結束了這個解決方案會:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="72dp" 
    android:background="@android:color/white"> 

    <ImageView 
     android:id="@+id/contact_item_image" 
     android:background="@android:color/black" 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_marginLeft="@dimen/left_margin" 
     android:layout_centerVertical="true" 
     /> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:layout_marginLeft="16dp" 
     android:paddingRight="@dimen/right_margin" 
     android:paddingBottom="20dp" 
     android:layout_alignParentBottom="true" 
     android:layout_toRightOf="@+id/contact_item_image" 
     > 
     <TextView 
      android:id="@+id/contact_item_prim_text" 
      android:text="Test title" 
      android:textSize="@dimen/subhead_txt_size" 
      android:textColor="@color/blackish" 
      android:singleLine="true" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      /> 

     <TextView 
      android:id="@+id/contact_item_sec_text" 
      android:text="Test sec title" 
      android:textSize="@dimen/body1_txt_size" 
      android:textColor="@color/android_greyish" 
      android:singleLine="true" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      /> 
    </LinearLayout> 
</RelativeLayout> 

這給了我的東西,看起來像這樣:

new version of design