android - 以编程方式添加的 TextView 不会重置为新行的屏幕开头
问题描述
我正在以编程方式在 RecyclerView 中添加的 ViewHolder 中添加 TextView。我面临的问题是在它到达屏幕末尾并转到新行之后,文本与屏幕开头没有对齐。
mHolder.mAuthorsContainer.removeAllViews();
int size = mData.mAuthors.mAuthorsHMap.size(), count = 1;
Typeface typeface = ResourcesCompat.getFont(mContext, R.font.zillaslab_bold);
for(Map.Entry<String, String> entry : mData.mAuthors.mAuthorsHMap.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
TextView mAuthor_ = new TextView(mContext);
mAuthor_.setTextColor(Color.parseColor("#3100A2"));
mAuthor_.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
mAuthor_.setTypeface(typeface);
mAuthor_.setTextSize(TypedValue.COMPLEX_UNIT_SP, CustomPreferences.getInstance(mContext).getmSpArticlePublishSize());
mAuthor_.setLineSpacing(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, CustomPreferences.getInstance(mContext).getmSpArticleTextLineSpacing(), mMetrics), 1.0f);
mAuthor_.setText(value);
mHolder.mAuthorsContainer.addView(mAuthor_);
}
mAuthorsContainer 是一个 LinearLayout 而父布局是 ConstraintLayout,仅此而已
尝试 setLines、setMaxLines、setGravity 到左侧,目前没有任何效果。
提前致谢。
解决方案
推荐阅读
- java - JMockit 模拟铸造
- python - 如何使用 tkinter 在我的 python 脚本中调用 tcl 命令?
- c# - 在 c# 中检查是否存在带有 json 响应正文的属性值
- linux - 每次集群启动时运行 SQL
- reinforcement-learning - 双深度 Q 学习中的 Q 值过冲
- leaflet - 使用传单在屏幕上有多个地图,想将其修复为单个
- laravel - 无法打开流或文件“/Applications/XAMPP/xamppfiles/htdocs/apcjobs/storage/logs/laravel-2020-06-06.log”:
- java - 为什么我的自定义 JPanel 没有被绘制/重新绘制,即使我正在从事件队列中绘制并覆盖 paintComponent()?
- flutter - 使用 Flutter 将图像拖到另一个图像之上
- c - 无效指针值在功能更改时不会更改