更改 TextView 中的 textSize [英] Change textSize in a TextView

查看:29
本文介绍了更改 TextView 中的 textSize的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面来自 android studio 上的 android 应用程序的这段代码中,我有一个包含 TextView 的 LinearLayout,我想将其大小更改为例如从 100 到 20.但问题是,每当我更改 android:textSize="100.0dip" 到任何其他数字,在我的手机上运行时,应用程序中的大小仍然保持不变.

In this code below from an android application on android studio, I have a LinearLayout that contains a TextView whose size I want to change for example say from 100 to 20. But the thing is, whenever I change the android:textSize="100.0dip" to any other number, the size still remains the same in the application when running it on my phone.

代码:

<ScrollView
    android:id="@id/qp_body_wrapper"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_above="@id/widget34"
    android:layout_below="@id/widget99"
    android:layout_marginBottom="5.0dip"
    android:layout_marginTop="10.0dip"
    android:clickable="true"
    android:focusable="true"
    android:foregroundGravity="right">

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@id/qp_body_wrapper_container"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:focusable="true"
        android:orientation="vertical">

        <TextView
            android:id="@id/qp_body"
            style="@style/QuoteViewText"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/dashboard_qod_bg"
            android:clickable="true"
            android:focusable="true"
            android:gravity="right"
            android:padding="10.0dip"
            android:textAlignment="viewEnd"
            android:textColor="#FFFFFF"
            android:textSize="100.0dip"
            tools:ignore="RtlCompat,RtlHardcoded" />
    </LinearLayout>
</ScrollView>

这里是 QuoteViewText 样式:

and here is the QuoteViewText style :

<style name="QuoteViewText">
        <item name="android:textSize">100.0dip</item>
        <item name="android:typeface">serif</item>
        <item name="android:textStyle">bold</item>
        <item name="android:textColor">#fffcfcfc</item>
        <item name="android:shadowColor">#ff102e46</item>
        <item name="android:shadowDx">0.0</item>
        <item name="android:shadowDy">1.0</item>
        <item name="android:shadowRadius">2.0</item>
    </style>

推荐答案

您在 textsize 中使用了 dip,而不是仅使用 dpsp.dp 和 sp 都可以工作,但通常在 textview 中,我们使用 sp .

You are using dip in textsize,instead of that just use dp or sp.dp and sp both will work but normally in textview ,we use sp .

这篇关于更改 TextView 中的 textSize的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆