我知道这应该是简单,但安卓scaleType =centerCrop不裁剪图像
我得到了图像的 1950年像素的宽,需要通过父母的宽度被裁剪。但安卓scaleType =centerCrop不裁剪图像。我需要什么做的布局,只显示第一个的 400像素的,例如或任何画面/父宽度
抱歉简单的问题 - 试图谷歌它 - 只有复杂的问题存在。而我是新的,所以不要downvote请)
< RelativeLayout的的xmlns:机器人=http://schemas.android/apk/res/android 的xmlns:工具=http://schemas.android/tools 机器人:ID =@ + ID / RL1 机器人:layout_width =match_parent 机器人:layout_height =match_parent 机器人:背景=@色/ background_color> < ImageView的 机器人:ID =@ + ID / ver_bottompanelprayer 机器人:layout_width =match_parent 机器人:layout_height =227px 机器人:layout_alignParentBottom =真 机器人:layout_alignParentLeft =真 机器人:scaleType =矩阵 机器人:背景=@可绘制/ ver_bottom_panel_tiled_long/> < / RelativeLayout的>如果有唯一的办法就是programmaticaly裁剪 - 请给我一个建议与方法
解决方案好吧,我会糊的评论,因为答案:) - >
RelativeLayout的RL =(RelativeLayout的)findViewById(R.id.rl1); 最后的选项bitmapOptions =新的选项(); bitmapOptions.inDensity =采样大小; bitmapOptions.inTargetDensity = 1; / *`final`改性剂可能是必要的位图* / BMP位= BitmapFactory.de codeResource(getResources(),R.drawable.ver_bottom_panel_tiled_long,bitmapOptions); bmp.setDensity(Bitmap.DENSITY_NONE); BMP = Bitmap.createBitmap(BMP,0,0,rl.getWidth(),bmp.getHeight());然后在code:
ImageView的IV =(ImageView的)v.findViewById(R.id.ver_bottompanelprayer); 如果(IV!= NULL){ iv.setImageBitmap(BMP); }
干杯:)
I know this should be simple , but android:scaleType="centerCrop" doesn't crop Image
I got image 1950 pixels wide and need it to be cropped by parent's width. But android:scaleType="centerCrop" doesn't crop Image. What do I need to do in layout to show only first 400 pixels, for instance or whatever screen/parent width is
Sorry for simple question - tried to Google it - only complicated questions there. And I'm new, so don't downvote please)
<RelativeLayout xmlns:android="schemas.android/apk/res/android" xmlns:tools="schemas.android/tools" android:id="@+id/rl1" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/background_color"> <ImageView android:id="@+id/ver_bottompanelprayer" android:layout_width="match_parent" android:layout_height="227px" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:scaleType="matrix" android:background="@drawable/ver_bottom_panel_tiled_long" /> </RelativeLayout>if there's only way is to programmaticaly crop it - please give me an advice with a method
解决方案Alright, I will paste the comment as answer :) ->
RelativeLayout rl = (RelativeLayout) findViewById(R.id.rl1); final Options bitmapOptions=new Options(); bitmapOptions.inDensity=sampleSize; bitmapOptions.inTargetDensity=1; /*`final` modifier might be necessary for the Bitmap*/ Bitmap bmp= BitmapFactory.decodeResource(getResources(), R.drawable.ver_bottom_panel_tiled_long, bitmapOptions); bmp.setDensity(Bitmap.DENSITY_NONE); bmp = Bitmap.createBitmap(bmp, 0, 0, rl.getWidth(), bmp.getHeight());Then in the code:
ImageView iv = (ImageView)v.findViewById(R.id.ver_bottompanelprayer); if (iv != null){ iv.setImageBitmap(bmp); }
Cheers :)
更多推荐
我如何裁剪位图ImageView的?
发布评论