【问题标题】:Android Text View - Top and Bottom edges clipped offAndroid 文本视图 - 顶部和底部边缘被剪掉
【发布时间】:2014-01-28 17:40:26
【问题描述】:

有人可以解释一下吗?
为什么第三个 TextView 很奇怪?

前面2行的定义都是一样的,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>

【问题讨论】:

  • 你能发布你的布局xml文件吗?

标签: android xml textview


【解决方案1】:

这是一种奇怪的行为。

尝试将“stepTwo”的内容设置为“stepThree”。 如果出现同样的问题,那么问题出在TextView。

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

【讨论】:

  • “内容”是什么意思?就像我说的:“我还没有接触过 java 的风格”......
  • 我的意思是textView里面的文字。
  • 所以,textView 中的文本问题。
【解决方案2】:

在 android Text View 中,当您尝试渲染下标时,文本会在顶部和底部被剪裁。为避免这种情况,您可以尝试从 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's subscript being clipped off

Subscript and Superscript a String in Android

【讨论】:

    【解决方案3】:

    您需要将 android:layout_height 更改为 TextView(因为所有 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" />
    

    【讨论】:

      猜你喜欢
      • 2018-10-14
      • 1970-01-01
      • 1970-01-01
      • 2014-04-13
      • 1970-01-01
      • 2014-06-05
      • 1970-01-01
      • 1970-01-01
      • 2021-12-22
      相关资源
      最近更新 更多