如何在Android中更改textview元素的字体大小?

问题描述:

我正在尝试在TextView中显示2个项目.他们有什么方法可以更改TextView中单个项目的字体吗?

I am trying to display 2 items in a TextView. Is their any way to change the font of the single item in a TextView?

这是我正在使用的XML

Here is the XML which I am using

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

    <TextView
        android:gravity="center_horizontal"
        android:paddingTop="5dp"
        android:paddingBottom="5dp"
        android:id="@+id/Rowtext"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:text="Listiems"
        android:background="@drawable/customshape"
         />

</LinearLayout>

使用android:textSize.

Use android:textSize.

<TextView
    android:id="@+id/time"
    android:gravity="right"
    android:padding="5dp"
    android:textSize="40dp"
    android:textColor="#88ffff00"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:text="Time: 60"/>

如果用户可以在不破坏UI的情况下重新缩放文本,请使用sp.如果重新缩放文本会破坏UI,请使用dp.

Use sp if the user can rescale the text without breaking the UI. If rescaling the text would break the UI, use dp.