Question

I have a RelativeLayout within a ScrollView, I am trying to move the textView, move it down or to the right but I can not find the way.

I tried with:

valueTV.setPadding(200, 500, 40, 100);

But the textView does not change its place

Paste my code:

        RelativeLayout layout = (RelativeLayout) findViewById(R.id.layout);
        TextView valueTV = new TextView(this);
        valueTV.setText("try txtVw");
        valueTV.setBackgroundColor(Color.CYAN);
        valueTV.setLayoutParams(new LayoutParams( 30,20));
//      valueTV.setPadding(200, 500, 40, 100); //It doesn't work//
        layout.addView(valueTV);

Thanks!

Was it helpful?

Solution

I think it will help you. try this.

TextView tv;
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                                                                 LayoutParams.WRAP_CONTENT);
lp.rightMargin = //RIGHTMARGIN;
lp.leftMargin = //LEFT MARGIN;
lp.topMargin = // TOP MARGIN;
lp.bottomMargin =  // BOTTOM MARGIN;
layout.addView(tv, lp);

OTHER TIPS

U have to use the XMl file in the res to design,its more easy and comfortable to design when compare to designing using java code as u have done. If u are using java code,make sure you enter corect coddinates as well as the size of tht textview is appropiate

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top