创建一个完全空的Drawable似乎是一个常见的需求,作为占位符,初始状态等,但似乎没有一个好方法来做到这一点......至少在XML中.有几个地方指的是系统资源,@android:drawable/empty但据我所知(即,它不在参考文档中,并且aapt chokes说它无法找到资源)这不存在.
有没有一种引用空Drawable的一般方法,或者你最终为每个项目创建一个虚假的空PNG?
我的Android应用程序中有一个GridView,其中包含许多ImageView.屏幕上的空间有限,我希望图像尽可能多地占用可用空间.不幸的是,GridView总是在ImageViews的外边缘留下5个像素的空屏幕空间(ImageViews之间的空间设置为水平/垂直间距并且行为正确).空白空间有点像ImageViews的边缘,但我无法摆脱它.有谁知道是什么导致了这个"边界"以及我如何摆脱它(或者至少让它变小)?谢谢.
更新:我通过在Adapter类的getView()方法中膨胀.xml文件来创建ImageViews.这是我正在膨胀的xml:
<ImageView
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#FF00FF" />
Run Code Online (Sandbox Code Playgroud)
我在我的布局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"/>
Run Code Online (Sandbox Code Playgroud)
这是问题的屏幕截图.我的GridView中的红色区域.紫色区域是我的ImageViews.显示的图像是一个简单的蓝色矩形,中心是透明的.图像是45x45像素(但我的应用程序只有30x30像素 - 稍后我会担心).紫色周围的红色边框是我想要消除的.
