我有一个像这样的图像 - >

我希望像这样展示 - >

然后我可以选择我能看到多少(0~1,0 =看不到,1 =整个图片,0.5 =半图片,等等,从用户输入读取)
怎么做?
我尝试使用android:scaleType但它不起作用.
tal*_*kol 25
我的建议是最好包装你BitmapDrawable用ClipDrawable.
ClipDrawable允许您为任何其他drawable定义剪裁,因此不会绘制整个drawable,而只会绘制其中的一部分.
那会怎么样?您的ImageView可以显示可绘制的 - 可分配的setImageDrawable().当然,您可以在其中放置图像位图的BitmapDrawable.如果你首先使用ClipDrawable包装你的BitmapDrawable,然后只分配给ImageView,你应该没问题.
<ImageView
android:id="@+id/imageView1"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/clip_source" />
Run Code Online (Sandbox Code Playgroud)
这是clip_source可绘的:
<?xml version="1.0" encoding="utf-8"?>
<clip xmlns:android="http://schemas.android.com/apk/res/android"
android:clipOrientation="vertical"
android:drawable="@drawable/your_own_drawable"
android:gravity="top" />
Run Code Online (Sandbox Code Playgroud)
您可以通过调用setLevel()ClipDrawable(clip_source)上的函数来定义裁剪量.级别0表示图像完全隐藏,级别10000表示图像完全显示.您可以在中间使用任何int值.
您必须在代码中设置级别,因此您的代码应该首先获得对ClipDrawable的引用.您可以通过getDrawable()在ImageView实例上运行来完成此操作.当你有一个ClipDrawable的引用时,只需运行setLevel(5000)它(或任何其他数字0-10000).
ImageView img = (ImageView) findViewById(R.id.imageView1);
mImageDrawable = (ClipDrawable) img.getDrawable();
mImageDrawable.setLevel(5000);
Run Code Online (Sandbox Code Playgroud)