繁体   English   中英

文字大小不同的Android手机

[英]text sizes different Android phones

由于我使用的是Nexus 5,因此我看到了一些有关文本大小的奇怪内容。

一个例子:我正在创建列表视图项。 我在22sp处输入较大的文本,在17sp处输入较小的文本。

在我的HTC One X上,它看起来像这样:

在此处输入图片说明

所以我认为“好,很好!”

然后在Nexus 5上运行它:

在此处输入图片说明

我不明白为什么会这样? 'sp'部分不应该确保使用默认值看起来可以吗? 我不是在谈论用户在设置中增加字体大小,而是将所有内容保留为默认值。

即使,如果我(不要打我)在这里使用DP来禁用文本的字体大小更改,它也会给出相同的结果(未经测试,但我可以肯定的是其他测试也是如此)。

这里有什么问题? 它是较新的Android版本,还是1080p屏幕与720p屏幕?

是否应该使用“值”文件夹为不同的DP使用不同的值?

这是布局:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="80dp"
    android:orientation="horizontal">

    <LinearLayout
        android:id="@+id/background"
        android:layout_marginTop="10dp"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">

        <com.android.volley.toolbox.NetworkImageView
            android:id="@+id/image"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:adjustViewBounds="true"
            android:scaleType="centerCrop" />

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_margin="5dp"
            android:layout_weight="2">

            <ImageView
                android:id="@+id/arrow"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_alignParentRight="true"
                android:adjustViewBounds="true" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="3dp"
                android:layout_toLeftOf="@id/arrow"
                android:gravity="center"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/name"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="1"
                    android:fontFamily="sans-serif-condensed"
                    android:textSize="22sp"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/address"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="1"
                    android:textSize="17sp" />
            </LinearLayout>
        </RelativeLayout>
    </LinearLayout>
</LinearLayout>

例如,相同SP值的默认大小可能会因设备而异,只是为了与其针对设备设计的可读性相匹配。

您遇到的问题是,因为有些元素的大小设置为固定大小,然后将用于行的XML代码发布出来,我们可以进行深入分析。

编辑-xml之后

好吧,我确实希望重新构建您的布局,而不是指出错误,请看一下:

<?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="wrap_content"
    android:layout_margin="10dp"
    android:orientation="horizontal" >

    <com.android.volley.toolbox.NetworkImageView
        android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="match_parent" />

    <TextView
        android:id="@+id/name"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/image"
        android:layout_toLeftOf="@+id/arrow"
        android:fontFamily="sans-serif-condensed"
        android:textSize="22sp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/address"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/image"
        android:layout_toLeftOf="@id/arrow"
        android:layout_below="@id/name"
        android:textSize="17sp" />

    <ImageView
        android:id="@id/arrow"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_alignParentRight="true" />
</RelativeLayout>

您的布局太复杂了,无法简单地排成一行……现在,布局将达到TextViews所需的高度,这不是问题,因为用户已经在使用其文本大小。

您必须创建两个不同的布局文件夹并查看结果

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM