gpt4 book ai didi

android - 将 textview 和 imageview 添加到在 android 中动态创建的线性布局

转载 作者:行者123 更新时间:2023-11-29 21:26:59 25 4
gpt4 key购买 nike

我需要将 textviewimageview 放置到 linearlayout 中。文本的内容是一个字符串数组,我在布局中获取不到文本,其他一切都很好我的代码是:

LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
TextView topicText = new TextView(this);
LinearLayout textLinear = new LinearLayout(this);
textLinear.setOrientation(LinearLayout.HORIZONTAL);
textLinear.setBackgroundDrawable(this.getResources().getDrawable(R.drawable.action_background_item));
topicText.setId(i);
topicText.setTextSize((float) 19.2);
topicText.setText((CharSequence) mStringArray[i]);
topicText.setTextColor(000000);
topicText.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.icon,0);
topicText.setLayoutParams(lp);
topicText.setTag(i);
textLinear.addView(topicText);
this.topLayout.addView(textLinear);

最佳答案

你真的给LinearLayout添加了TextView。但是您的 TextView 文本颜色为 0,这意味着透明颜色。因此,即使添加了 TextView,它也会让您感觉 TextView 不存在,因为它的颜色是透明的。将文本颜色更改为另一种颜色,如黑色 (0xFF000000)。可能这是你犯的错误......

关于android - 将 textview 和 imageview 添加到在 android 中动态创建的线性布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20116985/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com