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

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

linearLayout.addView(TextView) not working

问题

  1. private LinearLayout clmnView;
  2. clmnView = new LinearLayout(getContext());
  3. LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
  4. LinearLayout.LayoutParams.MATCH_PARENT,
  5. LinearLayout.LayoutParams.WRAP_CONTENT);
  6. int margin = DimensionsHelper.getMargins(getContext(), DimensionsHelper.DimensionType.BALL);
  7. params.setMargins(0, margin, 0, margin);
  8. clmnView.setLayoutParams(params);
  9. clmnView.setOrientation(LinearLayout.VERTICAL);
  10. clmnView.setGravity(Gravity.CENTER_VERTICAL);
  11. TextView historyTextView = new TextView(getContext());
  12. historyTextView.setLayoutParams(new LinearLayout.LayoutParams(
  13. LinearLayout.LayoutParams.WRAP_CONTENT,
  14. LinearLayout.LayoutParams.WRAP_CONTENT));
  15. historyTextView.setText("this is history");
  16. clmnView.addView(historyTextView);

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

英文:
  1. private LinearLayout clmnView;
  2. LinearLayout clmnView = new LinearLayout(getContext());
  3. LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
  4. LinearLayout.LayoutParams.MATCH_PARENT,
  5. LinearLayout.LayoutParams.WRAP_CONTENT);
  6. int margin = DimensionsHelper.getMargins(getContext(), DimensionsHelper.DimensionType.BALL);
  7. params.setMargins(0, margin, 0, margin);
  8. clmnView.setLayoutParams(params);
  9. clmnView.setOrientation(LinearLayout.VERTICAL);
  10. clmnView.setGravity(Gravity.CENTER_VERTICAL);
  11. TextView historyTextView = new TextView(getContext());
  12. historyTextView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
  13. LinearLayout.LayoutParams.WRAP_CONTENT));
  14. historyTextView.setText("this is history");
  15. 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

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

  1. 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 :

  1. 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:

确定