code set gravity in code

Try using this instead:

para.gravity = Gravity.CENTER_HORIZONTAL; tv2.setLayoutParams(para); //the below sets the view's content gravity, not the gravity //of the view itself. Since the width is wrap_content, this //has no effect. //tv2.setGravity(android.view.Gravity.CENTER_HORIZONTAL);

你可能感兴趣的:(android)