繁体   English   中英

图像按钮使应用程序崩溃

[英]Image Button crashes the app

当我将ImageButton添加到我的应用程序(它们没有背景)时,应用程序崩溃。 我有以下代码:

<ImageButton
    android:id="@+id/ib_main_home"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/home"
    android:background="@null"
    android:scaleType="fitCenter"
    />

<ImageButton
    android:id="@+id/ib_main_categories"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/categories"
    android:background="@null"
    android:scaleType="fitCenter"
    />

<ImageButton
    android:id="@+id/ib_main_actors"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/actors"
    android:background="@null"
    android:scaleType="fitCenter"
    />

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/twitter"
    android:background="@null"
    android:scaleType="fitCenter"
    />

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/facebook"
    android:background="@null"
    android:scaleType="fitCenter"
    />

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/instagram"
    android:background="@null"
    android:scaleType="fitCenter"
    />

(整个xml在RelativeLayout中 )...如果没有@null,则图像显示的尺寸大于屏幕尺寸。 然后Button会填满整个屏幕。 有人可以帮助我吗?

根据您的评论,该错误是java.lang.OutOfMemoryError,我怀疑您尝试加载到后台的一个或多个图像占用了太多内存,因为它们太大了 最简单的解决方案是将图像调整为较小的尺寸(这样也可以减小应用程序的尺寸)。 您可以手动调整大小,也可以使用在线提供的解决方案之一,例如: http : //resizeimage.net/

为了获得更好的效果,请删除wrap_content并缩放自己的图像。 您可以缩小源图像的大小。如果删除了wrap_content还可以删除background="@null"这可能会对您有所帮助。 请告诉我您如何组织这些ImageView。 您可以使用'merge'标签来创建复合视图,也请参见此链接

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM