2017-05-29 66 views
0

我已经通过了十几个这样的例子,与此有关的十几个错误,并由于某种原因,我的图像不工作。图像作为按钮背景 - 碰撞和工作

所有图像小于800x800像素,小于200kb,全部为.png格式。

我有几个片段与每个片段中的几个图像。 我已经添加了带有如下背景图片的按钮。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <TextView 
     android:id="@+id/textView2" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="Please select" /> 

    <Button 
     android:id="@+id/broad_btn" 
     android:layout_width="@android:dimen/notification_large_icon_width" 
     android:layout_height="@android:dimen/notification_large_icon_height" 
     android:background="@drawable/broad" 
     android:tag="broad" 
     android:text="Broad" /> 
    </Linearlayout> 

现在我所拥有的第二个片段上的图像与上面的图片没什么区别。 但是当我尝试在后台使用它时,我的应用崩溃了。

但是,如果我在第一页上使用“问题”图像 - 那么它工作正常。 只有当我将这张图片移动到第二个片段时,它才会失败。

第二的代码是

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <TextView 
     android:id="@+id/textView4" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="TextView" /> 

    <Button 
     android:id="@+id/late_btn" 
     android:layout_width="@android:dimen/notification_large_icon_height" 
     android:layout_height="@android:dimen/notification_large_icon_height" 
     android:background="@drawable/late" 
     android:text="Long" /> 
</LinearLayout> 
+0

什么错误你好吗? –

回答

0

对不起球员,

这是一个RAM问题,简单地说好的......给予足够的重视资源分配。

感谢, U.

0

最有可能你正在OutOfMemory误差大分辨率图像。

尝试使用GlidePicasso库来处理large照片efficiently以及磁盘caching

滑翔:

GlideApp.with(context).load(R.drawable.broad).into(imageView); 

毕加索:

icasso.with(context).load(R.drawable.late).into(imageView); 

希望这将有助于〜