linearLayout.addView(TextView)无法正常工作

huangapple 未分类评论61阅读模式
英文:

linearLayout.addView(TextView) not working

问题

private LinearLayout clmnView;
clmnView = new LinearLayout(getContext());
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
        LinearLayout.LayoutParams.MATCH_PARENT,
        LinearLayout.LayoutParams.WRAP_CONTENT);
int margin = DimensionsHelper.getMargins(getContext(), DimensionsHelper.DimensionType.BALL);
params.setMargins(0, margin, 0, margin);
clmnView.setLayoutParams(params);
clmnView.setOrientation(LinearLayout.VERTICAL);
clmnView.setGravity(Gravity.CENTER_VERTICAL);

TextView historyTextView = new TextView(getContext());
historyTextView.setLayoutParams(new LinearLayout.LayoutParams(
                     LinearLayout.LayoutParams.WRAP_CONTENT,
                     LinearLayout.LayoutParams.WRAP_CONTENT));
historyTextView.setText("this is history");
clmnView.addView(historyTextView);

无论我怎么做,historyTextView 都没有显示在 clmnView 内。你能帮忙看看吗?非常感谢。

英文:
private LinearLayout clmnView;
LinearLayout clmnView = new LinearLayout(getContext());
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
        LinearLayout.LayoutParams.MATCH_PARENT,
        LinearLayout.LayoutParams.WRAP_CONTENT);
int margin = DimensionsHelper.getMargins(getContext(), DimensionsHelper.DimensionType.BALL);
params.setMargins(0, margin, 0, margin);
clmnView.setLayoutParams(params);
clmnView.setOrientation(LinearLayout.VERTICAL);
clmnView.setGravity(Gravity.CENTER_VERTICAL);

TextView historyTextView = new TextView(getContext());
historyTextView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                     LinearLayout.LayoutParams.WRAP_CONTENT));
             historyTextView.setText("this is history");
clmnView.addView(historyTextView);

No matter what I do ,the historyTextView is not display inside my clmnView.
Could you please help? Thank you in advance.

答案1

得分: 0

好的,一切都按照预期工作。但是我在白色背景上显示白色文本。
像这样更改文本的颜色:

historyTextView.setTextColor(Color.parseColor("#000000"));

然后我的文本出现了。

英文:

Okay everything was working as it should. But I was displaying white text in white background.
Changed the color of the text like this :

historyTextView.setTextColor(Color.parseColor("#000000"));

and my text appeared.

huangapple
  • 本文由 发表于 2020年5月5日 18:58:24
  • 转载请务必保留本文链接:https://java.coder-hub.com/61611523.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定