2015-01-08 121 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