Drawable Rotating around its center Android

前端 未结 3 606
猫巷女王i
猫巷女王i 2020-12-13 06:45

I am getting strange results with the following code:

iv = (ImageView) findViewById(R.id.iv);
        iv.setImageResource(R.drawable.spinner_white_76);

             


        
3条回答
  •  余生分开走
    2020-12-13 07:10

    Note that this will not work if your object has asymmetric padding (for example a left padding of 5px and a right padding of 0px), because padding is considered part of the object. Which means the computed center will be offset.

    One solution to this is to use margins instead of padding if you are using padding for layout reasons. As the API says concerning margins: "This space is outside this view's bounds." (ViewGroup.MarginLayoutParams)

    This means that margins will not rotate as padding does.

提交回复
热议问题