android - 如何扩展 textView 并自动移动下一个字段?
问题描述
我正在该文本视图中从 firebase 检索大内容,但我只想显示 3 行,然后我想显示“readmore/showmore”选项,当使用点击该完整内容时,将显示完整内容,下一个字段将自动向下移动喜欢使用滚动视图!我的信息与下一个字段重叠,有人可以帮忙吗?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:expandableTextView="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:expandableTextView="http://schemas.android.com/apk/res-auto"
tools:context=".MoreDetails">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/cropimage"
android:layout_width="265dp"
android:layout_height="265dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:contentDescription="TODO"
android:scaleType="centerCrop" />
<TextView
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="300dp"
android:text="Description :"
android:textSize="20sp"
android:autoSizeTextType="uniform"
android:autoSizeMinTextSize="12sp"
android:autoSizeMaxTextSize="20sp"/>
<com.borjabravo.readmoretextview.ReadMoreTextView
android:id="@+id/description_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="330dp"
android:textSize="15sp"
app:trimCollapsedText="@string/read_more"
app:trimExpandedText="@string/read_less"
app:trimMode="trimModeLength"
app:trimLength="180"
app:colorClickableText="#000"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="100"
android:paddingTop="430dp">
<TextView
android:id="@+id/planting_time"
android:layout_width="match_parent"
android:layout_height="100dp"
android:text="planting time :"
android:gravity="center"
android:textSize="20sp"
android:layout_weight="60" />
<TextView
android:id="@+id/planting_time_info"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:autoSizeTextType="uniform"
android:autoSizeMinTextSize="12sp"
android:autoSizeMaxTextSize="20sp"
android:maxLines="16"
android:layout_weight="40"/>
</LinearLayout>
<View
android:layout_width="wrap_content"
android:layout_height="2dp"
android:background="@color/colorPrimary"
android:layout_marginTop="420dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="100"
android:paddingTop="530dp">
<TextView
android:id="@+id/bloom_time"
android:layout_width="match_parent"
android:layout_height="100dp"
android:text="bloom time :"
android:gravity="center"
android:textSize="20sp"
android:layout_weight="60" />
<TextView
android:id="@+id/bloom_time_info"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:autoSizeTextType="uniform"
android:autoSizeMinTextSize="12sp"
android:autoSizeMaxTextSize="20sp"
android:maxLines="16"
android:layout_weight="40"/>
</LinearLayout>
<View
android:layout_width="wrap_content"
android:layout_height="2dp"
android:background="@color/colorPrimary"
android:layout_marginTop="530dp"/>
解决方案
喜欢描述有maxLines=3
<TextView
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="300dp"
android:text="Description :"
android:textSize="20sp"
android:maxLines="3"
android:autoSizeTextType="uniform"
android:autoSizeMinTextSize="12sp"
android:autoSizeMaxTextSize="20sp"/>
现在您想在单击后将行添加到文本行,然后在 java 中执行此操作
description.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
description.setLines(description.getLineCount());
}
});
希望它会奏效
谢谢!快乐编码!
推荐阅读
- c++ - 验证输入是否在范围内
- node.js - findOneAndUpdate 异步等待不返回新文档
- reactjs - React Admin - 具有多个字段输出的 ReferenceInput
- git - 从 git 克隆文件会出现错误“参数过多”
- c# - 获取枚举实例给定它的自定义属性的值
- c - 读取完整目录时的递归函数不会“进入目录”
- javascript - 将表格从 React 导出为 PDF
- javascript - ngModel 在表单中使用时不更新
- python - 用于检查文件名是否存在于文本文件中的 Python 代码
- tensorflow - 为 TensorFlow v2 创建时间序列数据集