Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
HBHAndroid
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
杨秀秀
HBHAndroid
Commits
06169a71
Commit
06169a71
authored
Oct 26, 2023
by
小费同学阿
💬
Committed by
杨秀秀
Nov 21, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
68069 【企业app-android】我的评论列表记录超过两行显示效果不正确
parent
471ecaa3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
141 additions
and
17 deletions
+141
-17
MyCommentListAdapter.java
...xx/hbhbcompany/activity/adapter/MyCommentListAdapter.java
+17
-1
ExpandTextView.kt
...main/java/com/xx/hbhbcompany/ui/comment/ExpandTextView.kt
+105
-0
MyCommentViewModel.java
...ava/com/xx/hbhbcompany/ui/comment/MyCommentViewModel.java
+9
-6
item_comment_list.xml
hbhbcompany/src/main/res/layout/item_comment_list.xml
+10
-10
No files found.
hbhbcompany/src/main/java/com/xx/hbhbcompany/activity/adapter/MyCommentListAdapter.java
View file @
06169a71
...
...
@@ -4,8 +4,18 @@ package com.xx.hbhbcompany.activity.adapter;
import
static
com
.
xx
.
hbhbcompany
.
utils
.
RetrofitClient
.
baseImgUrl
;
import
android.content.Context
;
import
android.text.Layout
;
import
android.text.SpannableString
;
import
android.text.SpannableStringBuilder
;
import
android.text.Spanned
;
import
android.text.StaticLayout
;
import
android.text.TextUtils
;
import
android.text.style.AlignmentSpan
;
import
android.text.style.ForegroundColorSpan
;
import
android.util.Log
;
import
android.view.View
;
import
android.view.ViewTreeObserver
;
import
android.widget.TextView
;
import
com.bumptech.glide.Glide
;
import
com.bumptech.glide.load.resource.bitmap.RoundedCorners
;
...
...
@@ -14,6 +24,7 @@ import com.xx.hbhbcompany.R;
import
com.xx.hbhbcompany.data.http.respons.MyCommentBean
;
import
com.xx.hbhbcompany.data.staticdata.StaticData
;
import
com.xx.hbhbcompany.databinding.ItemCommentListBinding
;
import
com.xx.hbhbcompany.ui.comment.ExpandTextView
;
import
com.xx.xxviewlibrary.base.xxBaseRecyclerViewAdapter
;
import
me.jessyan.autosize.utils.AutoSizeUtils
;
...
...
@@ -32,6 +43,9 @@ public class MyCommentListAdapter extends xxBaseRecyclerViewAdapter<ItemCommentL
@Override
protected
void
covert
(
ItemCommentListBinding
dataBind
,
MyCommentBean
data
,
int
position
)
{
ExpandTextView
ex
=
new
ExpandTextView
(
mContext
)
.
setMaxLine
(
2
);
ex
.
show
(
dataBind
.
tvCommentContent
,
data
.
getCommentContent
());
// 将接口调出来的布局遍历上去
dataBind
.
setMyCommentBean
(
data
);
Log
.
v
(
"评论列表的重要信息:"
,
String
.
valueOf
(
data
));
...
...
@@ -49,5 +63,7 @@ public class MyCommentListAdapter extends xxBaseRecyclerViewAdapter<ItemCommentL
/*隐藏删除按钮*/
dataBind
.
ivAapDelete
.
setVisibility
(
View
.
GONE
);
}
}
}
}
\ No newline at end of file
hbhbcompany/src/main/java/com/xx/hbhbcompany/ui/comment/ExpandTextView.kt
0 → 100644
View file @
06169a71
package
com.xx.hbhbcompany.ui.comment
import
android.content.Context
import
android.graphics.Color
import
android.text.Layout
import
android.text.SpannableString
import
android.text.Spanned
import
android.text.StaticLayout
import
android.text.style.ForegroundColorSpan
import
android.widget.TextView
import
com.xx.hbhbcompany.R
class
ExpandTextView
(
var
context
:
Context
)
{
// 默认展示行数,超过多少行隐藏
private
var
maxLine
:
Int
=
2
// 文本左右边距总合
private
var
margin
:
Int
=
0
// 展开、收起文本颜色
private
var
colorStr
:
String
=
"#5971A4"
// 展开显示文本
private
var
expandStr
:
String
=
"【展开更多】"
// 收起显示文本
private
var
foldStr
:
String
=
"【收起】"
fun
setMaxLine
(
maxLine
:
Int
):
ExpandTextView
{
this
.
maxLine
=
maxLine
return
this
}
fun
setMargin
(
margin
:
Int
):
ExpandTextView
{
this
.
margin
=
margin
return
this
}
fun
setColorStr
(
colorStr
:
String
):
ExpandTextView
{
this
.
colorStr
=
colorStr
return
this
}
fun
setFoldStr
(
foldStr
:
String
):
ExpandTextView
{
this
.
foldStr
=
foldStr
return
this
}
fun
setExpandStr
(
expandStr
:
String
):
ExpandTextView
{
this
.
expandStr
=
expandStr
return
this
}
fun
show
(
expandTextView
:
TextView
,
content
:
String
)
{
// 裁剪函数来去除前导空格
expandTextView
.
text
=
content
.
trimIndent
()
// 获取TextView的画笔对象
val
paint
=
expandTextView
.
paint
// 每行文本布局宽度: 屏幕宽度 - 左右边距
val
width
=
context
.
resources
.
displayMetrics
.
widthPixels
-
context
.
resources
.
getDimension
(
R
.
dimen
.
fab_margin
).
toInt
()
val
fontColor
=
ForegroundColorSpan
(
Color
.
parseColor
(
colorStr
))
// 实例化StaticLayout
val
staticLayout
=
StaticLayout
(
content
,
paint
,
width
,
Layout
.
Alignment
.
ALIGN_NORMAL
,
1f
,
0f
,
false
)
// 判断content行数是否超过最大限制行数
if
(
staticLayout
.
lineCount
>
maxLine
)
{
/**
* 展开后的文本内容
*/
val
str
=
(
"$content\t\t$foldStr"
)
val
expandSpanStr
=
SpannableString
(
str
)
expandSpanStr
.
setSpan
(
fontColor
,
str
.
length
-
6
,
str
.
length
,
Spanned
.
SPAN_EXCLUSIVE_EXCLUSIVE
)
//获取最后一个文字的下标
val
index
=
staticLayout
.
getLineStart
(
maxLine
)
-
1
/**
* 收起后的文本内容
*/
val
str2
=
(
"${content.substring(0, index - 6)}...$expandStr"
)
val
foldSpanStr
=
SpannableString
(
str2
)
foldSpanStr
.
setSpan
(
fontColor
,
str2
.
length
-
6
,
str2
.
length
,
Spanned
.
SPAN_EXCLUSIVE_EXCLUSIVE
)
//设置收起后的文本内容
expandTextView
.
text
=
foldSpanStr
expandTextView
.
setOnClickListener
{
if
(
expandTextView
.
isSelected
)
{
//收起的状态
expandTextView
.
text
=
expandSpanStr
expandTextView
.
isSelected
=
false
}
else
{
//展开的状态
expandTextView
.
text
=
foldSpanStr
expandTextView
.
isSelected
=
true
}
}
//设成选中状态 true收起状态,false展示状态
expandTextView
.
isSelected
=
true
}
else
{
//未超过最大限制行数,直接设置文本
expandTextView
.
text
=
content
expandTextView
.
setOnClickListener
(
null
)
}
}
}
\ No newline at end of file
hbhbcompany/src/main/java/com/xx/hbhbcompany/ui/comment/MyCommentViewModel.java
View file @
06169a71
package
com
.
xx
.
hbhbcompany
.
ui
.
comment
;
import
android.app.Application
;
import
android.view.View
;
import
android.widget.TextView
;
import
androidx.annotation.NonNull
;
import
androidx.lifecycle.MutableLiveData
;
...
...
@@ -39,7 +41,7 @@ public class MyCommentViewModel extends ListBaseViewModel<MyCommentRequest> {
//调用我的评论列表接口信息
public
void
getMyCommentList
()
{
model
.
getMyCommentList
(
status
,
page
)
model
.
getMyCommentList
(
status
,
page
)
.
compose
(
RxUtils
.
schedulersTransformer
())
//线程调度
.
doOnSubscribe
(
MyCommentViewModel
.
this
)
.
doOnSubscribe
(
new
Consumer
<
Disposable
>()
{
...
...
@@ -62,18 +64,19 @@ public class MyCommentViewModel extends ListBaseViewModel<MyCommentRequest> {
public
void
onError
(
String
Error
)
{
dismissDialog
();
}
@Override
public
void
getTotal
(
int
total
)
{
if
(
total
==
0
)
{
if
(
total
==
0
)
{
loadMoreStatic
.
postValue
(
3
);
}
else
if
(
myCommentListAdapter
.
mList
.
size
()>=
total
)
{
}
else
if
(
myCommentListAdapter
.
mList
.
size
()
>=
total
)
{
loadMoreStatic
.
postValue
(
2
);
}
else
{
}
else
{
loadMoreStatic
.
postValue
(
1
);
}
}
});
}
}
hbhbcompany/src/main/res/layout/item_comment_list.xml
View file @
06169a71
...
...
@@ -51,18 +51,18 @@
</LinearLayout>
<!--评论内容-->
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:orientation=
"horizontal"
>
<TextView
android:id=
"@+id/tv_comment_content"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:orientation=
"horizontal"
>
<TextView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:gravity=
"left"
android:text=
"@={myCommentBean.commentContent}"
android:textColor=
"#333333"
android:textSize=
"16dp"
/>
</LinearLayout>
android:text=
"@={myCommentBean.commentContent}"
android:textColor=
"#333333"
android:textSize=
"16dp"
/>
</LinearLayout>
</LinearLayout>
<!--评论封面.标题-->
<LinearLayout
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment