Android GridView:充气布局后未显示图像视图/图像按钮
我尝试使用自定义项布局在GridView中显示平铺。每个都有一个文本视图以及下面的三个图像按钮。 XML项布局如下所示。在Android Studio designer中,布局完全符合我的要求Android GridView:充气布局后未显示图像视图/图像按钮,android,android-layout,android-gridview,Android,Android Layout,Android Gridview,我尝试使用自定义项布局在GridView中显示平铺。每个都有一个文本视图以及下面的三个图像按钮。 XML项布局如下所示。在Android Studio designer中,布局完全符合我的要求 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.an
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView" />
<LinearLayout
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="@drawable/ic_edit" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="@drawable/ic_play" />
<ImageView
android:id="@+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="@drawable/ic_remove" />
</LinearLayout>
</LinearLayout>
定义的平铺大小为180 x 180确实足够大,在运行时,图像应该位于的位置有大量的空白空间
你知道会出什么问题吗
提前感谢您您正在使用的图像资源是矢量,您需要在build.gradle文件中进行一些更改。加
vectorDrawables.useSupportLibrary = true
在build.gradle文件中的defaultConfig下
android {
defaultConfig {
...
...
vectorDrawables.useSupportLibrary = true //add this
}
}
在活动中添加这行代码
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
现在,您可以使用
app:srcCompat
而不是android:src
设置向量。您在内部LinearLayout
中添加了很多weightSum=“3”
谢谢,一定是其他内容。我按照建议添加了weightSum,没有任何更改。然后我取下了砝码。没有效果。一种解决方案是将所有矢量绘图更改为PNG或添加矢量支持。如果您确认我可以将其作为您问题的答案,请在build.gradle文件的“defaultConfig”下添加vectorDrawables.useSupportLibrary=true
,然后重试
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);