简体   繁体   English

可绘制不显示

[英]Drawable not showing up

I have a fairly simple xml file that has an image button in it.我有一个相当简单的 xml 文件,其中有一个图像按钮。 The image shows up fine on the Graphical Layout xml designer, shows up fine when I run a development build, but as soon as I create the signed apk file and run it, the image no longer shows up.该图像在图形布局 xml 设计器上显示良好,在我运行开发构建时显示良好,但是一旦我创建签名的 apk 文件并运行它,图像就不再显示。 It's just an empty button.它只是一个空按钮。 I can't think of a reason why, any ideas?我想不出原因,有什么想法吗? The xml file looks like this: xml 文件如下所示:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/navigation_root"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/navigation_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="5dp"
        android:text="TextView"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <SeekBar
        android:id="@+id/navigation_seekbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_weight="1"
        android:padding="5dp" />

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="5dp" >

        <ImageButton
            android:id="@+id/part_select_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/chapter_select" />

        <Button
            android:id="@+id/navigation_ok_button"
            android:layout_width="75dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="@string/ok" />

        <Button
            android:id="@+id/navigation_cancel_button"
            android:layout_width="75dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="@string/cancel" />
    </LinearLayout>
</LinearLayout>

The image @drawable/chapter_select is a fairly small (41*41) png file that is in the res/drawable folder.图片@drawable/chapter_select是一个相当小的 (41*41) png 文件,位于 res/drawable 文件夹中。

Seems like this is a bug with android, where sometimes the first image in the drawable folder doesn't show up. 似乎这是android的一个错误,有时可绘制文件夹中的第一个图像没有显示。 Added a dummy image called aaaa.png to the drawable folder and problem was solved. 向可绘制文件夹添加了一个名为aaaa.png的虚拟图像,问题得以解决。 Found the answer here: ImageButton does not display a particular drawable 在这里找到答案: ImageButton不显示特定的可绘制对象

Had the same issue and resolved it by removing all special characters. 发生了相同的问题,并通过删除所有特殊字符解决了该问题。 In my case it was dashes '-' in the filename: 在我的情况下,文件名中的破折号“-”:

background-720.png => background.png . background-720.png => background.png

One of the reason is 原因之一是

If you are using Vector file as a drawable left or right then you have to use . 如果将Vector文件用作可绘制的左侧或右侧,则必须使用。

android.support.v7.widget.AppCompatButton android.support.v7.widget.AppCompatButton

Instead Of 代替

Button 纽扣

Simple View like Button,Textview doesn't support Vector file as a Drawable left right in my case Button,Textview这样的简单视图在我的情况下不支持Vector文件作为Drawable left right

try to put the image in drawable-hdpi and drawable-mdpi folder depends on what device you run you app , the image is searched in these folders... 尝试将图像放在drawable-hdpi和drawable-mdpi文件夹中,具体取决于您运行应用的设备,在这些文件夹中搜索图像...

But puting in drawable means that the image should be available everywhere, but somethimes (depends on your manifest settings) this could not be true, I mean you can turn of the compatibility mode. 但是放入drawable意味着图像应该随处可见,但是某些主题(取决于清单设置)可能不正确,我的意思是可以切换兼容模式。

also you can try dinamically at run time to set the image to the view 您也可以在运行时尝试尝试将图像设置为视图

iv.setImageResource(R.drawable.somethig);

My situation was weird.Everything was correct until integrating FireBase Crash report to my Application. 我的情况很奇怪。在将FireBase Crash报告集成到我的应用程序之前,一切都是正确的。

I just added compile 'com.google.firebase:firebase-crash:11.0.1' & DrawableLeft vanished .When i went through the xml , noticed a warning (In lined below). 我刚刚添加了编译'com.google.firebase:firebase-crash:11.0.1'DrawableLeft都消失了 。当我通过xml时,注意到一个警告(在下面的行中)。

So added android:drawableStart & issue gone. 因此添加了android:drawableStart &问题。

Still I am wondering about the relation of FireBase Crash reporting to the same. 我仍然想知道FireBase崩溃报告与此之间的关系。

Using left/right instead of start/end attributes Using Gravity#LEFT and Gravity#RIGHT can lead to problems when a layout is rendered in locales where text flows from right to left. 使用左/右而不是开始/结束属性使用Gravity#LEFT和Gravity#RIGHT可能会导致在文本从右向左流动的语言环境中呈现布局时导致问题。 Use Gravity#START and Gravity#END instead. 请改用Gravity#START和Gravity#END。

Similarly, in XML gravity and layout_gravity attributes, use start rather than left. 同样,在XMLgravity和layout_gravity属性中,使用start而不是left。 For XML attributes such as paddingLeft and layout_marginLeft, use paddingStart and layout_marginStart. 对于paddingLeft和layout_marginLeft等XML属性,请使用paddingStart和layout_marginStart。

NOTE: If your minSdkVersion is less than 17, you should add both the older left/right attributes as well as the new start/right attributes. 注意:如果您的minSdkVersion小于17,则应同时添加较旧的left / right属性和新的start / right属性。 On older platforms, where RTL is not supported and the start/right attributes are unknown and therefore ignored, you need the older left/right attributes. 在较旧的平台上,其中不支持RTL并且start / right属性是未知的,因此被忽略,因此您需要较旧的left / right属性。

There is a separate lint check which catches that type of error. 有一个单独的lint检查可以捕获这种类型的错误。 (Note: For Gravity#LEFT and Gravity#START, you can use these constants even when targeting older platforms, because the start bitmask is a superset of the left bitmask. Therefore, you can use gravity="start" rather than gravity="left|start".) (注意:对于Gravity#LEFT和Gravity#START,即使在定位较旧的平台时也可以使用这些常量,因为起始位掩码是左侧位掩码的超集。因此,可以使用gravity =“ start”而不是gravity =“左|开始”。)

Check your image size. 检查图像尺寸。 If you're using an unnecessarily large asset when actually deployed it might just not show despite looking correct in the designer. 如果您在实际部署时使用了不必要的大型资产,则即使在设计器中看起来正确,它也可能不会显示。

Well ! 好 ! in my case setting MinifyEnabled false and shrinkResources false is working fine now. 在我的情况下,将MinifyEnabled设置为false ,将rinkResources设置为false ,现在可以正常工作。

i was getting image from drawable. 我正在从可绘制图像。 it was working pretty nice in debug version but after release version of apk it was showing sometime blank ImageView. 它在调试版本中工作得很好,但是在apk的发行版本之后,它有时显示为空白的ImageView。

minifyEnabled false shrinkResources true

** **

See the Screenshots 见截图

** **

**之前** **后**

Hope this may help anyone. 希望这可以帮助任何人。

I had a similar problem where a drawable png was not showing up in Android Studio.我遇到了类似的问题,Android Studio 中没有显示可绘制的 png。 Deleted the file and added it again in the drawable folder and it Worked for me.删除了文件并将其再次添加到可绘制文件夹中,它对我有用。

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

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