且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何实现一个机器人:背景不拉伸?

更新时间:2023-11-19 08:13:58

您应该使用ImageView如果你不希望它舒展。 背景图片总是会延伸到适合的视图。 您需要将其设置为可绘制的图像纵横强制的对象。

You should use ImageView if you don't want it to stretch. Background images will always stretch to fit the view. You need to set it as a Drawable to force the image aspect to the object.

另外,如果你采用按钮的想法,那么你就需要从拉伸力的比例在按钮prevent的形象。

Otherwise, if you are sticking with the Button idea, then you will need to force the scaling in the button to prevent the image from stretching.

如您

OnCreate(Bundle bundle) {
  //set content layout, etc up here

  //now adjust button sizes
  Button B = (Button) findViewById(R.id.somebutton);
  int someDimension = 50; //50pixels
  B.setWidth(someDimension);
  B.setHeight(someDimension);
}