【发布时间】:2014-03-11 14:40:59
【问题描述】:
简单的布局
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0099cc"
tools:context="com.testzoom.app.FullscreenActivity">
<TextView android:id="@+id/fullscreen_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:keepScreenOn="true"
android:textColor="#33b5e5"
android:textStyle="bold"
android:textSize="50sp"
android:gravity="center"
android:text="@string/dummy_content" />
<Button android:id="@+id/dummy_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/dummy_button"
android:layout_gravity="bottom"
/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:id="@+id/dummy_image"
/>
</FrameLayout>
目标 - 通过按下底部的按钮,将图像视图(与屏幕大小相同)设置为一半大小的截图位图。结果 - 奇怪的渲染,为什么 fitXY 不起作用?
点击处理程序:
findViewById(R.id.dummy_button).setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
View view = getWindow().getDecorView();
Bitmap bmp = Bitmap.createBitmap(view.getWidth()/2, view.getHeight()/2, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(bmp);
c.scale(0.5f,0.5f, bmp.getWidth(), bmp.getHeight());
view.draw(c);
((ImageView)findViewById(R.id.dummy_image)).setImageBitmap(bmp);
}
});
截图结果:
请注意,这个任务是合成的,所以不要问我为什么要这样做,这只是问题的演示。
【问题讨论】:
标签: android android-layout bitmap imageview