Tag: imageview

Android:OutofMemoryError:位图大小超过虚拟机预算,没有任何理由,我可以看到

我有一个超过600×800像素JPEG的画廊OutOfMemoryexception。 环境 我一直在用600×800像素的JPG图片来使用Gallery。 由于我的内容可能比图片稍微复杂一些,因此我将每个视图都设置为一个将ImageView换成JPG的RelativeLayout。 为了“加快”用户体验,我有一个简单的4槽高速caching(在循环中),左边1个图像和右边1个图像预取到显示的图像,并保留在4槽HashMap中。 该平台 我正在使用256 RAM和128堆大小的AVD,以及600×800的屏幕。 它也发生在Entourage Edge目标上,除了使用设备更难debugging。 问题 我已经得到一个例外: OutofMemoryError: bitmap size exceeds VM budget 当获取第五张图片时会发生这种情况。 我试图改变我的图像caching的大小,它仍然是一样的。 奇怪的事情:不应该有一个记忆问题 为了确保堆的限制与我所需要的距离相去甚远,我在开始时定义了一个虚拟的8MB数组,并将其保留为未引用状态,以便立即派发。 它是活动线程的成员,定义如下 static { @SuppressWarnings("unused") byte dummy[] = new byte[ 8*1024*1024 ]; } 结果是堆大小接近11MB,而且全部是免费的。 注意我开始崩溃后添加了这个技巧。 这使得OutOfMemory不那么频繁。 现在,我正在使用DDMS。 就在崩溃之前(在崩溃之后变化不大),DDMS显示: ID Heap Size Allocated Free %Used #Objects 1 11.195 MB 2.428 MB 8.767 MB 21.69% 47,156 […]

从布局xml文件旋转ImageView源

我在我的布局中有这个ImageView: <ImageView android:layout_width="fill_parent" android:layout_height="wrap_content" android:contentDescription="@string/image_divider" android:paddingBottom="8dp" android:paddingTop="4dp" android:scaleType="fitXY" android:src="@android:drawable/divider_horizontal_textfield" /> 这是一个水平分隔线。 我想旋转90度,所以我有一个垂直分频器。 有没有任何可能的方式在这里从布局,而不是活动课?

为什么我的Android GridView附近有额外的像素?

我的Android应用程序中有一个GridView,里面有很多ImageView。 我的屏幕上的空间是有限的,我希望图像占用尽可能多的可用空间。 不幸的是,GridView总是在ImageViews的外边缘留下5个像素的空屏幕空间(ImageViews之间的空间被设置为水平/垂直间距并且行为正确)。 空的空间就像ImageViews周围的边缘,但我无法摆脱它。 有谁知道是什么原因造成这个“边界”,我怎么能摆脱它(或至less使其更小)? 谢谢。 更新:我通过在Adapter类的getView()方法中扩展.xml文件来创buildImageView。 这里是我膨胀的XML: <ImageView xmlns:android="http://schemas.android.com/apk/res/android" android:background="#FF00FF" /> 我在我的布局XML文件中定义了GridView,像这样: <GridView android:id="@+id/mygrid" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_above="@+id/abutton" android:layout_marginBottom="8dp" android:numColumns="5" android:background="#FF0000"/> 这是一个问题的屏幕截图。 在我的GridView的红色区域。 紫色区域是我的ImageViews。 正在显示的图像是一个简单的蓝色矩形,透明的中心。 图像是45×45像素(但在我的应用程序只有30×30像素 – 我会后面担心)。 紫色周围的红色边框是我想要消除的。

如何在ImageView中获取Drawable的尺寸?

在ImageView中检索Drawable的尺寸的最佳方法是什么? 我的ImageView有一个Init-Method我创buildImageView: private void init() { coverImg = new ImageView(context); coverImg.setScaleType(ScaleType.FIT_START); coverImg.setImageDrawable(getResources().getDrawable(R.drawable.store_blind_cover)); addView(coverImg); } 在布局或测量过程中的某一时刻,我需要Drawable的确切尺寸来调整我周围的组件的其余部分。 coverImg.getHeight()和coverImg.getMeasuredHeight()不返回我需要的结果,如果我使用coverImg.getDrawable().getBounds()我得到的尺寸之前,由ImageView缩放。 谢谢你的帮助!

Android:在XML中调整imageview的大小

我有一个太大的图像,不适合在屏幕上,我希望它在屏幕上相当小。 我如何通过XML更改图像的大小? 我试过了: <ImageView android:id="@+id/image" android:layout_width = "100dp" android:layout_height= "100dp" android:scaleType="center" android:layout_gravity="center_horizontal|bottom" android:src="@drawable/dashboard_rpm_bottom" > </ImageView> 但图像没有resize…它被裁剪。 有任何想法吗?

canvas:试图在Android中使用回收的位图android.graphics.Bitmap

我正在裁剪图像类,但遇到一个回收的位图问题: 03-02 23:14:10.514: E/AndroidRuntime(16736): FATAL EXCEPTION: Thread-1470 03-02 23:14:10.514: E/AndroidRuntime(16736): java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@428e5450 03-02 23:14:10.514: E/AndroidRuntime(16736): at android.graphics.Canvas.throwIfRecycled(Canvas.java:1026) 03-02 23:14:10.514: E/AndroidRuntime(16736): at android.graphics.Canvas.drawBitmap(Canvas.java:1096) 03-02 23:14:10.514: E/AndroidRuntime(16736): at android.graphics.Bitmap.createBitmap(Bitmap.java:604) 03-02 23:14:10.514: E/AndroidRuntime(16736): at eu.janmuller.android.simplecropimage.CropImage$1.prepareBitmap(CropImage.java:630) 03-02 23:14:10.514: E/AndroidRuntime(16736): at eu.janmuller.android.simplecropimage.CropImage$1.run(CropImage.java:636) 03-02 23:14:10.514: E/AndroidRuntime(16736): at eu.janmuller.android.simplecropimage.CropImage$6.run(CropImage.java:343) 03-02 23:14:10.514: E/AndroidRuntime(16736): at eu.janmuller.android.simplecropimage.Util$BackgroundJob.run(Util.java:175) 03-02 […]

如何在突出显示或点击时突出显示ImageView?

一个很好的例子是在Twitter的启动屏幕上(当应用程序第一次启动时显示大图标的屏幕),或者当您关注应用程序图标时,甚至只是查看应用程序托盘。 基本上我需要突出显示一个ImageView,ImageView中图像的高亮轮廓,看起来像是该图像的边框。 我也想自定义突出显示,使其成为某种颜色,并淡化。 谢谢, groomsy

ImageView中带有圆angular的位图

我有一个ImageView,我想使它与rounded corners 。 我使用这个: <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="@null"/> <stroke android:width="1dp" android:color="#ff000000"/> <corners android:radius="62px"/> </shape> 并将此代码设置为我的imageview的背景。 它的工作原理,但是我放在ImageView上的src图像是走出了边界,并不适应新的形状。 我该如何解决这个问题?

图像视图不包裹内容

我有一个ImageView包装这个图像 : <ImageView android:layout_height="wrap_content" android:layout_width="wrap_content" android:scaleType="fitStart" android:src="@drawable/oncmap"/> 并在它下面,一个TextView。 不幸的是,它可能会根据设备的屏幕尺寸将其推到视图或视图外。 View post on imgur.com View post on imgur.com 我可以“破解”它,但宁可不… <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="16dp" android:orientation="vertical" tools:context="MapFragment"> <ImageView android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="@drawable/oncmap"/> <TextView android:layout_height="wrap_content" android:layout_width="fill_parent" android:text="Neptune" style="@style/sectionHeader"/> <TextView android:layout_height="wrap_content" android:layout_width="fill_parent" android:paddingLeft="8dp" android:paddingRight="8dp" android:paddingTop="16dp" android:text="@string/info" style="@style/text"/>

以编程方式将imageview的高度设置为matchparent

我需要将imageview的高度设置为matchparent编程方式。如果它是一个固定的高度,我知道如何设置。 但我怎么能把它设置为matchparent? 编辑: 实际上父布局的高度dynamic.so我需要使imageview的高度作为父母的高度。