Closed smelfungus closed 6 years ago
Can you provide your xml ? I will test it in my demo~~~
Hi, @lsjwzh. Sure. Here goes the ViewHolder:
<?xml version="1.0" encoding="utf-8"?>
<com.lsjwzh.widget.text.ReadMoreTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tv_layout_item_fast_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:ellipsize="end"
android:maxLines="3" />
Adapter:
public static class Adapter extends RecyclerView.Adapter<Adapter.ViewHolder> {
private final List<String> items = new ArrayList<>();
Adapter(List<String> items) {
this.items.addAll(items);
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.layout_item_fast_text_view, parent, false);
return new ViewHolder(
view
);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.bind(
items.get(position)
);
}
@Override
public int getItemCount() {
return items.size();
}
public static class ViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.tv_layout_item_fast_text_view)
ReadMoreTextView readMoreTextView;
public ViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
readMoreTextView.setCustomEllipsisSpan(new ReadMoreTextView.EllipsisSpan("... more"));
readMoreTextView.setCustomCollapseSpan(new ReadMoreTextView.EllipsisSpan(" less"));
}
public void bind(String text) {
readMoreTextView.setText(text);
}
}
}
RecyclerView:
recyclerView.setHasFixedSize(true);
Adapter adapter = new Adapter(
new ArrayList<String>() {{
add("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.");
}}
);
recyclerView.setLayoutManager(
new LinearLayoutManager(
this,
LinearLayoutManager.VERTICAL,
false
)
);
recyclerView.setAdapter(adapter);
Here is the layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_activity_fast_text_view_recycler_test"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.constraint.ConstraintLayout>
Here is the video: https://drive.google.com/file/d/19h54VWtS5rjh-87WMj83HXFkvzpDFMLu/view?usp=drivesdk
resolved
Hi there! Thank you for that wonderful library. Seems like EllipsisSpan clickable region is failing when attempting to use it in ViewHolders specifying margins for ReadMoreTextView with no exact width specified _(matchparent/0dp in ConstraintLayout). Any ideas? Thank you!