简体   繁体   中英

Android : How can I have XML layout and the views that I added to my layout?

I have a relative layout and some textviews in it... I defined this relative layout in the java, and add a view to it. but in the result I just have the view that I added to layout .. and it doesn't show any text boxes..

SampleView sample= new SampleView(this);
rl=(RelativeLayout) findViewById(R.id.rl);
rl.addView(sample);    

how can I fix it? (in this code, it just shows the sample view's object ... not textviews that I have in the layout)

Debugging is your solution.

  • Make sure that the view that you are adding does not overlap your textView.
  • Make sure your textview has text. Try checking its size in run time.

And finally use Android Studio layouting tool, to have a preview of your layout. You can use tools to generate something suitable for preview.

I solved it. my mistake was:

canvas.drawColor(Color.WHITE); 

in the onDraw ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM