如何在TextView中使用方向箭头

huangapple go评论85阅读模式
英文:

How to use directional arrows in TextView

问题

以下是翻译好的内容:

TextView中正确使用方向箭头的方法是什么,而无需创建可绘制对象?虽然考虑了Unicode,但不清楚需要使用哪些字符代码。无论是用于HTML还是以编程方式,左、右、上和下箭头分别必须使用哪个代码?理想情况下,要实现与下面截屏中使用的箭头相同的效果(注意,它们的自动大小调整和行内定位是正确的)。

如何在TextView中使用方向箭头

如何在TextView中使用方向箭头

英文:

What's the correct way to use directional arrows within a TextView without having to create a drawable? Unicode has been thought of but it's not clear which character codes need be used. What code must be used both for HTML and programmatically for the left, right, up & down arrows? Ideally to get the same result as the arrows used in the screenshots below (notice how they are correctly autosized and positioned in line as the text).

如何在TextView中使用方向箭头

如何在TextView中使用方向箭头

答案1

得分: 0

你是对的,你可以像下面这样使用Unicode

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:orientation="vertical">

    <androidx.appcompat.widget.AppCompatTextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="→ right" />

    <androidx.appcompat.widget.AppCompatTextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="← left" />

    <androidx.appcompat.widget.AppCompatTextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="↑ top" />

    <androidx.appcompat.widget.AppCompatTextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="↓ bottom" />
</LinearLayout>

我使用了这个网站,里面有很多箭头符号的数据,可以在这里查看。

英文:

You are right you can use Unicode like below

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
android:id=&quot;@+id/container&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;match_parent&quot;
android:layout_gravity=&quot;center&quot;
android:orientation=&quot;vertical&quot;&gt;


&lt;androidx.appcompat.widget.AppCompatTextView
    android:id=&quot;@+id/textView1&quot;
    android:layout_width=&quot;wrap_content&quot;
    android:layout_height=&quot;wrap_content&quot;
    android:layout_gravity=&quot;center&quot;
    android:text=&quot;&amp;#8594; right&quot; /&gt;


&lt;androidx.appcompat.widget.AppCompatTextView
    android:id=&quot;@+id/textView2&quot;
    android:layout_width=&quot;wrap_content&quot;
    android:layout_height=&quot;wrap_content&quot;
    android:layout_gravity=&quot;center&quot;
    android:text=&quot;&amp;#8592; left&quot; /&gt;


&lt;androidx.appcompat.widget.AppCompatTextView
    android:id=&quot;@+id/textView3&quot;
    android:layout_width=&quot;wrap_content&quot;
    android:layout_height=&quot;wrap_content&quot;
    android:layout_gravity=&quot;center&quot;
    android:text=&quot;&amp;#8593; top&quot; /&gt;

&lt;androidx.appcompat.widget.AppCompatTextView
    android:id=&quot;@+id/textView4&quot;
    android:layout_width=&quot;wrap_content&quot;
    android:layout_height=&quot;wrap_content&quot;
    android:layout_gravity=&quot;center&quot;
    android:text=&quot;&amp;#8595; bottom&quot; /&gt;
&lt;/LinearLayout&gt;

I use this site it has a lot of data for arrows section check here

huangapple
  • 本文由 发表于 2020年5月5日 04:56:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/61601466.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定