2015-08-15 72 views
1

我试图在设计我的应用程序时遵循Google的设计指南。我想创建一个单行列表,并且我遵循this page上的指导原则,对于纯文本单行列表。为什么我的布局不符合Google的Material Design Guidelines?

这里是规格:

Font: Roboto Regular 16sp 
Tile height: 48dp 
Text padding, top: 16dp 
Text padding, bottom: 20dp 

Bottom padding is measured from the baseline. 

和这也显示出左右填充图片:

Single-line list

这里是下面的规格后,我得到的结果:

My Result

正如你所看到的,它会被切断。谁在错误?这是我的布局文件:

<?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="48dp" 
    android:orientation="vertical"> 

    <TextView 
     android:id="@+id/textView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="Single-line item" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:textSize="16sp" 
     android:paddingTop="16dp" 
     android:paddingBottom="20dp" 
     android:paddingLeft="16dp" 
     android:paddingRight="16dp"/> 

</RelativeLayout> 

我试图消除android:textAppearance线,但它只是改变了文本的颜色。

这里有什么问题?为什么我的布局不符合Google的指南?

+0

我认为问题在'底部填充是从基线测量'。我会考虑简单地使用顶部填充 – njzk2

+0

@ njzk2好的,这就是我要做的。我只是困惑,为什么它似乎没有工作,当我认为我正确地遵循设计指南。 –

回答

0

在这种情况下,您确实不需要指定填充。父级布局具有固定的高度,因此您可以简单地使TextView包装其内容并将其垂直居中放在其父级中。

<?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="48dp"> 

    <TextView 
     android:id="@+id/textView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_centerVertical="true" 
     android:text="Single-line item" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:textSize="16sp"/> 

</RelativeLayout> 

一般来说,当我确实需要一些量的视图的内容移位我只使用填充。虽然大多数时候,适当的布局参数(对齐,重力,边距等)就足够了。