0

我的要求是在屏幕底部显示一半的车轮图像。我无法剪切图像,因为我需要在运行时旋转它。我已经尝试了相对布局的不同选项(通过将其设置为 alignParentBottom 为 true 并提供 -ve 边距底部)、线性布局(通过提供边距)。它适用于普通 mdpi(320X480)、hdpi(480X800) 设备。但是当设备的高度增加(如 480X870)时,整个轮子都会显示出来。

车轮图像是

车轮图像

屏幕应该看起来像

输出画面

需要这方面的帮助。提前致谢。

4

3 回答 3

0

您始终可以通过静态方法裁剪您需要的部分Bitmap.createBitmap(),然后将其分配给视图:

就像是...

// Set some constants
private static final Bitmap SOURCE_BITMAP = BitmapFactory.decodeFile(....); // Get the source Bitmap using your favorite method :-)
private static final int START_X = 10;
private static final int START_Y = 15;
private static final int WIDTH_PX = 100;
private static final int HEIGHT_PX = 100;

// Crop bitmap
Bitmap newBitmap = Bitmap.createBitmap(SOURCE_BITMAP, START_X, START_Y, WIDTH_PX, HEIGHT_PX, null, false);

// Assign new bitmap to ImageView
ImageView image = (ImageView)findViewById(R.id.image_view);
image.setImageBitmap(newBitmap);

在这里,您SOURCE_BITMAP是您的原始转向图像。

我希望这有帮助。

于 2013-05-08T09:24:02.627 回答
0

在 xml 文件中设置 android:translationY="300dp"。

这会将图像移动到底部

于 2019-02-06T12:36:32.723 回答
0

First set imageview align bottom in relative layout in xml file. Then set imageview margin programmatically by half (or ratio you want) of imageview height.

int height = imageview.getHeight();
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.WRAP_CONTENT,
                RelativeLayout.LayoutParams.WRAP_CONTENT
        );
        params.setMargins(0, height/2, 0, 0);
        imageview.setLayoutParams(params);

于 2019-02-06T13:43:44.757 回答