在listview中Android材料设计混乱

Rey*_*ohn 4 android material-design

我正在为材料设计指定的listview行设计2行文本布局.

Primary text font: Roboto Regular 16sp
Secondary text font: Roboto Regular 14sp
Tile height: 72dp
Text padding, left: 16dp
Text padding, top and bottom: 20dp
Run Code Online (Sandbox Code Playgroud)

它在android studio设计视图的显示中显示正常但是当我在我的7inch samsung选项卡上运行时,它被裁剪为这样 在此输入图像描述 我知道如果你把一些dp从这里移到那里然后这个问题将被修复,但在此之前我只想知道如果我做错了或guidline是否有任何关于平板电脑DP值的特殊章节?

Zie*_*ony 11

Material Design不适用于程序员,也适用于设计人员.这就是为什么准则难以实施.

在您的情况下,您应该记住,在指南中,他们使用Roboto字体的基线和上升线.仅使用两个TextView和简单的填充,您无法真正创建与规范匹配的布局.

在此输入图像描述

我想你的布局应该是这样的:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="#ffffffff"
    android:paddingLeft="16dp"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="72dp">

    <TextView
        android:layout_alignParentTop="true"
        android:layout_marginTop="20dp"
        android:paddingTop="11dp"
        android:id="@+id/topMarker"
        android:layout_width="1dp"
        android:layout_height="1dp"
        android:textSize="1dp" />

    <TextView
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="20dp"
        android:padding="0dp"
        android:gravity="center"
        android:id="@+id/bottomMarker"
        android:layout_width="1dp"
        android:layout_height="1dp"
        android:textSize="1dp" />

    <TextView
        android:layout_alignBaseline="@+id/topMarker"
        android:text="Primary text"
        android:textSize="16sp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <TextView
        android:layout_alignBaseline="@+id/bottomMarker"
        android:text="Secondary text"
        android:textSize="14sp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

对齐辅助文本很容易,但主要文本非常棘手,因为Android无法与ascender行对齐.您可以测量上升和偏移顶部标记,或者只是使主文本的上边距变小.

编辑:

我写了一篇关于对齐文本的文章.它涵盖了使用标记视图进行文本对齐,并很好地解决了此线程的问题.它可以在这里找到:https://androidreclib.wordpress.com/2016/03/10/aligning-text-on-android/