Android 安卓:可绘制的不显示
我有一个相当简单的xml文件,其中有一个图像按钮。该图像在图形布局xml设计器上显示良好,在运行开发构建时显示良好,但一旦创建并运行签名的apk文件,该图像就不再显示。这只是一个空按钮。我想不出原因,有什么想法吗?xml文件如下所示:Android 安卓:可绘制的不显示,android,image,button,Android,Image,Button,我有一个相当简单的xml文件,其中有一个图像按钮。该图像在图形布局xml设计器上显示良好,在运行开发构建时显示良好,但一旦创建并运行签名的apk文件,该图像就不再显示。这只是一个空按钮。我想不出原因,有什么想法吗?xml文件如下所示: <?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="
<?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" >
</TextView>
<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" >
</SeekBar>
<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" >
</ImageButton>
<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>
<Button
android:id="@+id/navigation_cancel_button"
android:layout_width="75dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@string/cancel" >
</Button>
</LinearLayout>
图像
@drawable/chapter_select
是一个相当小的(41*41)png文件,位于res/drawable文件夹中。尝试将图像放入drawable hdpi和drawable mdpi文件夹中
根据您运行应用程序的设备,将在这些文件夹中搜索图像
但是放入drawable意味着图像应该在任何地方都可用,但有时(取决于清单设置)这不可能是真的,我的意思是你可以打开兼容模式
您还可以在运行时尝试手动将图像设置为视图
iv.setImageResource(R.drawable.somethig);
这似乎是android的一个bug,有时候drawable文件夹中的第一个图像不会显示。在drawable文件夹中添加了一个名为aaaa.png的虚拟图像,问题得到了解决。在这里找到答案:有相同的问题,并通过删除所有特殊字符来解决。在我的例子中,文件名中是破折号“-”:
background-720.png=>background.png
我的情况很奇怪。在将FireBase崩溃报告集成到我的应用程序之前,一切都是正确的
我刚刚添加了compile'com.google.firebase:firebase-crash:11.0.1'
&DrawableLeft消失了。当我浏览xml时,注意到一个警告(在下面的行中)
因此添加了android:drawableStart
&问题消失。
我仍然想知道FireBase崩溃报告与该公司的关系
使用左/右,而不是使用重力左的开始/结束属性
而重力#RIGHT在渲染布局时可能会导致问题
文本从右向左流动的区域设置。使用重力#启动和关闭
重力反而结束了
类似地,在XML重力和布局重力属性中,使用start
而不是离开。用于XML属性,如paddingLeft和
左侧,使用paddingStart和layout_-marginStart
注意:如果您的minSdkVersion小于17,则应同时添加
旧的左/右属性以及新的开始/右属性。
在较旧的平台上,不支持RTL,并且启动/启动正确
属性是未知的,因此被忽略,您需要旧的
左/右属性
有一个单独的lint检查来捕获该类型的错误。
(注意:对于重力#左和重力#开始,您可以使用这些常量。)
即使针对较旧的平台,因为起始位掩码是
左位掩码的超集。因此,可以使用gravity=“start”
而不是重力=“左|开始”。)
检查您的图像大小。如果您在实际部署时使用了不必要的大型资产,那么尽管在设计器中看起来正确,但它可能不会显示出来。好吧!在我的例子中,设置MinifyEnabled false和shrinkResources false现在工作正常 我从drawable那里得到图像。它在调试版本中运行得很好,但在apk发布版本之后,它有时会显示空白的ImageView
minifyEnabled false
shrinkResources true
**
看到截图了吗
**
希望这对任何人都有帮助 原因之一是
如果要使用矢量
文件作为可绘制的左侧或右侧,则必须使用
android.support.v7.widget.AppButton
而不是
钮扣
像
按钮这样的简单视图,Textview
不支持矢量文件作为可绘制的左右
在我的情况下我不想把它放在特定的屏幕密度文件夹中,因为我希望所有设备都能够使用图像而不进行复制。动态设置映像不会改变任何东西,它仍然不会显示在已签名的构建中。谢谢你的努力。