我一直在尝试创建一个可以显示多个用户消息的活动,为了让所有内容都能适应文本视图,我需要创建三行。我在网上搜索没有得到任何解决方案,以下是我尝试过的:
Java
"\n"
"\r\n"
newLineChar = System.getProperty("line.separator")
messageTextView.setText(Html.fromHtml("This\n Is\n A Test"));
messageTextView.setText(Html.fromHtml("This<br> Is<br> A Test"));
xml
android:lines="3"
android:maxLines="3"
杂项。
- 将字符串值直接硬编码到setText()中
- 所有上述组合
- 移除android:clickable="false"
- 移除android:cursorVisible="false"
- 移除android:focusable="false"
- 移除android:focusableInTouchMode="false"
代码片段:
// Message passed to next activity via putExtra()
message = "This\n Is\n A Test";
// Next Activity
TextView messageTextView = (TextView) findViewById(R.id.messageToUser);
String message = getIntent().getStringExtra("message");
messageTextView.setText(message);
TextView的当前和更新的XML:
<TextView
android:id="@+id/messageToUser"
android:layout_width="0dp"
android:layout_height="200dp"
android:background="#90FFFFFF"
android:ems="10"
android:fontFamily="serif"
android:text=""
android:textAlignment="center"
android:textColor="@android:color/black"
android:textSize="30sp"
android:textStyle="bold"
tools:layout_constraintTop_creator="1"
tools:layout_constraintRight_creator="1"
android:layout_marginStart="165dp"
android:layout_marginEnd="165dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginTop="209dp"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
如果有帮助的话,我使用的是Windows 7操作系统,Android Studio版本为2.3.2,Java版本是1.8。我正在设计一款专门用于SM-T580 (三星Tab A 10.1英寸平板电脑)的应用程序,TextView的父级是组件树中基础的ConstraintLayout。
ems
和inputType
。 - Nitin Patel