How to set both gravity and layout gravity of a LinearLayout programatically

Short answer Set gravity linearLayout.setGravity(Gravity.CENTER); Set layout gravity // the LinearLayout’s parent is a FrameLayout FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(400, 400); params.gravity = Gravity.TOP|Gravity.RIGHT; linearLayout.setLayoutParams(params); Background Previously, I have explained the difference between ‘gravity’ and `layout_gravity’ for views within a layout. Setting the gravity of a LinearLayout itself changes the location of the views within … Read more

How do you properly implement gravity to a free floating space object and some sort of friction when thrusting in opposite direction

When you press UP you don’t have to change the speed, but you have to set the acceleration: self.vel = vec(PLAYER_SPEED, 0).rotate(-self.rot) self.acc += vec(PLAYER_ACC, 0).rotate(-self.rot) Add the acceleration to the velocity: self.vel += self.acc I recommend limiting the maximum. However, I recommend doing this separately for each direction: max_vel = 2 self.vel[0] = max(-max_vel, … Read more