Android GridLayout项之间的间距
我在运行时有一个GridLayout(不是GridView) 这是我的xmlAndroid GridLayout项之间的间距,android,space,grid-layout,Android,Space,Grid Layout,我在运行时有一个GridLayout(不是GridView) 这是我的xml <?xml version="1.0" encoding="utf-8"?> <GridLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/grid" android:layout_width="match_parent" android:layout_he
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/grid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:rowCount="4"
android:columnCount="3"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
>
</GridLayout>
我在运行时添加itmes。项目是一个包含图像和文本的类,一切都很好。
我需要在项目之间留一个空格(与GridView相同)
我怎样才能做到这一点呢?先试试这个
选择器\网格视图\项目\图像\蓝色.xml
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/gridview_item_image_border_blue_phone" android:state_pressed="true"/>
<item android:drawable="@drawable/image_border" android:state_focused="true"/>
<item android:drawable="@drawable/image_border"/>
</selector>
gridview\项目\图像\边框\蓝色\手机.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="@color/blue" />
<stroke
android:width="4dp"
android:color="@color/blue" />
<padding
android:bottom="4dp"
android:left="4dp"
android:right="4dp"
android:top="4dp" />
</shape>
尝试在它们之间设置边距。您可以为每个项目使用“形状”样式,并在其中添加填充。如果需要添加实际间距,则形状将没有帮助。从视觉上看,它可能是一样的,是的,但在结构上它不是,对吗?使用权重时,边距也没有帮助(至少在appcompat v24版本中没有)