Android TextView background does not move when TextView.Padding changes

I have a TextView that I created in main.xml. In my app.java, I dynamically position the TextView based on where the user takes the screen. The problem I'm running into is that when I call myTextView.setPadding (100,100,0,0), it moves the actual TextView text, but doesn't move the color background of the TextView.

Ideas?

+2


a source to share


3 answers


The padding only affects the content of the view, you can inline your view in the LinearLayout and change the padding of the LinearLayout to move the TextView.



+2


a source


If you want to move all of the content, you can use margins instead.



0


a source


You can use animation to move the view.

Animation a = new TranslateAnimation((oldPos),
                 newPos, 0.0f, 0.0f);
        a.setDuration(300);
        a.setStartOffset(100);
        a.setRepeatMode(Animation.ABSOLUTE);
        a.setFillAfter(true);

        a.setInterpolator(AnimationUtils.loadInterpolator(this.getContext(),
                        android.R.anim.accelerate_decelerate_interpolator));

 View.startAnimation(a);

      

0


a source







All Articles