安卓文本视图-顶部和底部边缘被裁剪

3

有人可以解释一下吗?为什么第三个TextView看起来很奇怪?
enter image description here

前两行定义相同,我没有通过Java更改样式...

编辑:我已经添加了XML布局文件。 XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/rl"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="top" >

    <TextView
        android:id="@+id/quadEqu"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="25dp"
        android:text="@string/quadequ"
        android:textSize="27sp" />

    <Button
        android:id="@+id/closeBtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="30dp"
        android:text="@string/close"
        android:onClick="close" />

    <TextView
        android:id="@+id/stepOne"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/quadEqu"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="25dp"
        android:text="@string/quadEquForm"
        android:textSize="18sp" />

    <TextView
        android:id="@+id/stepTwo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/stepOne"
        android:layout_below="@+id/stepOne"
        android:text="@string/quadEquForm"
        android:textSize="18sp" />

    <TextView
        android:id="@+id/stepThree"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/stepOne"
        android:layout_below="@+id/stepTwo"
        android:text="@string/quadEquForm"
        android:textSize="18sp" />

</RelativeLayout>

1
你能发布你的布局XML文件吗? - Yjay
3个回答

0
在Android的TextView中,当您尝试呈现下标时,文本会在顶部和底部被裁剪。为了避免这种情况,您可以尝试从HTML设置文本。
例如:
stepThree.setText(Html.fromHtml("Some text<sup><small>1</small></sup>"));

stepThree.setText(Html.fromHtml(
        "HCO<sub><small><small>3</small></small></sub>));

请参考以下链接获取更多详细信息。

Android TextView 的下标被裁剪

在 Android 中对字符串进行上标和下标处理


0

你需要更改TextViewandroid:layout_height属性(最好是全部3个都修改)。

<TextView
    android:id="@+id/stepOne"
    android:layout_width="wrap_content"
    android:layout_height="30dp"
    android:layout_below="@+id/quadEqu"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="25dp"
    android:text="@string/quadEquForm"
    android:textSize="18sp" />

<TextView
    android:id="@+id/stepTwo"
    android:layout_width="wrap_content"
    android:layout_height="30dp"
    android:layout_alignLeft="@+id/stepOne"
    android:layout_below="@+id/stepOne"
    android:text="@string/quadEquForm"
    android:textSize="18sp" />

<TextView
    android:id="@+id/stepThree"
    android:layout_width="wrap_content"
    android:layout_height="30dp"
    android:layout_alignLeft="@+id/stepOne"
    android:layout_below="@+id/stepTwo"
    android:text="@string/quadEquForm"
    android:textSize="18sp" />

0

这是一种奇怪的行为。

尝试将“stepTwo”的内容设置为“stepThree”的内容。 如果出现相同的问题,则问题来自TextView。

您应该检查是否以编程方式修改了“stepThree” textView的填充。


“Content”指的是“内容”的意思吗? 就像我说的:“我还没有用Java改过样式”… - Eyal
我指的是textView中的文本。 - Mahmoud
所以,textView 中的文本存在问题。 - Mahmoud

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接