在我的Android项目中,我有一个显示长文本的TextView.我想在行之间给出一些空格,就像我们在CSS中使用line-height属性一样.我们应该怎么做?
我基于计时器每隔0.5秒在TextView上设置一些文本.每次,当计时器运行并且设置了文本时,我在控制台中收到此警告消息.
W/StaticLayout:maxLineHeight不应为-1.maxLines:1 lineCount:1
XML代码:
<RelativeLayout 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">
<TextView
android:id="@+id/title_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:layout_marginTop="12dp"
android:ellipsize="end"
android:maxLines="1"
android:textColor="@color/white"/>
<TextView
android:id="@+id/time_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingEnd="4dp"
android:paddingStart="12dp"
android:textColor="@color/white"
android:textSize="12sp"
tools:text="0:00" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
Java代码:
public void setProgress() {
// setProgress() called every 0.5 seconds
// Hardcoded text
mTimeText.setText("0:05");
}
Run Code Online (Sandbox Code Playgroud) 我可以知道 android xml 中 lineHeight 和 lineSpacingExtra 之间有什么区别吗?我试图比较两者,但得到了不同的结果(我需要 lineHeight 函数,但它仅在 API 28 中受支持)。
这是我的代码的一部分:
剩下:
android:textSize="14sp"
android:lineSpacingExtra="6dp"
对:
android:textSize="14sp"
android:lineHeight="20dp"
结果:
有什么解决办法吗?谢谢你。
我正在尝试制作这样的布局:
|---------------------------| |---------------------------|
| Title of text goes there | | Title of text goes there |
|---------------------------| |---------------------------|
| Image goes there, height | | Image goes there, height |
| can be different | | can be different, very |
|---------------------------| | very, very different |
| Long, very long text goes | |---------------------------|
| here, and here, and here | | Long, very long text goes |
| that should fill space | | here, and here, …Run Code Online (Sandbox Code Playgroud)