我正在处理我的 android 项目,以在两个文本视图中输入文本并在 http://127.0.0.1:8000/api/todos
[
{
"id": 14,
"title": "First",
"description": "first",
"completed": false
},
{
"id": 15,
"title": "Second",
"description": "second item",
"completed": false
},
{
"id": 16,
"title": "Third",
"description": "third item",
"completed": false
}
]
文本视图旁边显示 Inbox
文本。我的 textview 有问题,因为当文本又短又大时,它不会移动 textview 旁边的 email_subject
。
这是它显示的内容:
这是我想要实现的目标:
这里是 content_main.xml:
Inbox
能否请您举例说明,当文本短而大时,如何让 <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:orientation="horizontal">
<FrameLayout
android:id="@+id/flString"
android:layout_width="295dp"
android:layout_height="135dp"
tools:layout_editor_absoluteX="10dp"
tools:ignore="MissingConstraints">
<TextView
android:id="@+id/email_subject"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_marginTop="19dp"
android:text="Mail delivery failed: returning message to sender"
android:textColor="#757575"
android:textSize="20sp"
android:textStyle="bold" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/mailbox_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/rounded_mailbox"
android:text="Inbox"
android:textColor="#757575"
android:textSize="12sp"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true" />
</RelativeLayout>
</FrameLayout>
<ImageView
android:id="@+id/ivFavorite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="284dp"
android:layout_marginTop="16dp"
android:padding="5dp"
android:src="@drawable/ic_star_black_24dp"
app:layout_constraintHorizontal_bias="0.723"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/more_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="284dp"
android:layout_marginTop="54dp"
android:padding="5dp"
android:src="@drawable/ic_baseline_3_dots_24"
app:layout_constraintHorizontal_bias="0.723"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/from_me"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="72dp"
android:layout_marginTop="8dp"
android:text="to me"
android:textColor="#757575"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/from_sender" />
<ImageView
android:id="@+id/dropdown_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="114dp"
android:layout_marginTop="8dp"
android:src="@drawable/ic_arrow_down"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/from_sender" />
</androidx.constraintlayout.widget.ConstraintLayout>
文本显示在文本末尾?
编辑:当我尝试这个时:
Inbox
它不会将收件箱文本移动到文本的末尾。有什么想法吗??
答案 0 :(得分:0)
一个想法是像下面一样使用 Spannable
TextView textView = rootView.findViewById(R.id.email_subject);
String subject = "RE: SRX1517391641ID - [EXTERNAL] Re: Reported deliverability problem to Outlook.com SRX1517391641ID ";
subject = subject + "Inbox";
Spannable wordtoSpan = new SpannableString(subject);
wordtoSpan.setSpan(new BackgroundColorSpan(Color.LTGRAY), subject.length() - 5, subject.length(), Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
wordtoSpan.setSpan(new StyleSpan(Typeface.NORMAL), subject.length() - 5, subject.length(), Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
wordtoSpan.setSpan(new RelativeSizeSpan(0.7f), subject.length() - 5, subject.length(), Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
textView.setText(wordtoSpan);
注意:这只是一个基本示例,如果您认为值得探索,这只是为您提供一些探索的想法。
注意:您可以探索https://github.com/googlearchive/android-text/tree/master/RoundedBackground-Kotlin
并且还可以研究关于在此处制作跨度的解决方案https://stackoverflow.com/a/19297086/4828650