如何创建上标类型的TextView,如图所示

问题描述 投票:1回答:3

我想在android中创建像这个图像的Textview。是否可以在单个文本视图中创建它.enter image description here

android android-layout textview
3个回答
1
投票

尝试以下方式在textview中实现上标

((TextView)findViewById(R.id.text)).setText(Html.fromHtml("<sup>10260</sup>"));

0
投票

UPDATE尝试Spannable String,如下所示:

 SpannableString styledString = new SpannableString("10260");

 // superscript
    styledString.setSpan(new SuperscriptSpan(), 3, 5, 0);

   // Give the styled string to a TextView
    TextView textView = (TextView) findViewById(R.id.text);
    textView.setText(styledString);

-1
投票

这个问题暂时搁置这里是我的解决方案,我通过在约束布局中使用两个不同大小的TextView解决了这个问题。没有其他解决方案适合我。

 <?xml version="1.0" encoding="utf-8"?>
    <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="-15dp">

        <TextView
            android:id="@+id/balance_amount_tv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:text="107"
            android:textSize="94sp"
            app:layout_constraintStart_toEndOf="@+id/dollar_tv"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/balance_superscript_amount_tv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="2.5dp"
            android:layout_toRightOf="@+id/balance_amount_tv"
            android:text="50"
            android:textSize="60sp"
            app:layout_constraintBottom_toBottomOf="@+id/balance_amount_tv"
            app:layout_constraintStart_toEndOf="@+id/balance_amount_tv"
            app:layout_constraintTop_toTopOf="@+id/balance_amount_tv"
            app:layout_constraintVertical_bias="0.3" />

    </android.support.constraint.ConstraintLayout>
© www.soinside.com 2019 - 2024. All rights reserved.