2013-11-21 76 views
0

我需要将textviewimageview设置为linearlayout。文本的内容是一个字符串array.I无法得到在布局中的文字,其他一切都是精细 我的代码是:将textview和imageview添加到在android中动态创建的线性布局

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); 
+0

我添加了linearlayout到父 – info

+0

所以你的问题是如何从资源中的字符串数组获取值? – NickF

+0

是啊需要显示该线性布局创建的文本和图像,但不幸的是文本不显示:( – info

回答

2

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

+0

非常感谢为确切的答案:) – info

相关问题