开发者

Why is programatic layout invisible?

my TextView that I add to my LinearLayout is not visible...why ?

layoutVenues = (LinearLayout) findViewById(R.id.开发者_如何学JAVAlayoutv);
layoutVenues.addView(genTextView(v.getName()));
layoutVenues.addView(genLineView());

and the genTextView Method:

public TextView genTextView(String text) {
        TextView tv = new TextView(this);
        tv.setText(text);
        tv.setTextColor(Color.BLACK);
        return tv;
    }


You need to set layout parameters otherwise you will not have a proper layout

public TextView genTextView(String text) {
     TextView tv = new TextView(this);
     LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutPararms.WRAP_CONTENT);
     tv.setLayoutParams(lp);
     tv.setText(text);
     tv.setTextColor(Color.BLACK);
     return tv;
    }


Try to add visiblity to your view. .setVisibility(View.VISIBLE);

or place it in your xml and instantiating in the code will also be good idea.


I build most of my view hierarchies for Android using XML layout files, so I'm not an expert on programmatically assembling view hierarchies. However, one thing that jumps out at me is that you don't appear to set any layout parameters on the TextView that is returned by genTextView(). Also, take a look at the layout parameters of the LinearLayout in your XML file and make sure that it is actually getting assigned screen real estate.


The default background is black I believe? So you have black text on a black background. Its probably not that easy though :P Might want to post the xml where the linearlayout is defined.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜