【发布时间】:2014-02-25 08:38:52
【问题描述】:
这就是我的网格视图的样子: a http://imageshack.com/a/img41/7857/roir.png 我使用一些在线 JSON 解析并获取图像缩略图链接,然后将其作为数组传递给自定义适配器并设置图像,我再次使用一些第 3 方库等。但第 3 方库仅用于设置图像到图像视图。就是这样。
所以我有一个主要的 FragmentActivity。它里面有2个碎片。您看到的文本框在一个片段(搜索片段)内,在它上面,gridview 由第二个片段保存。 (结果片段)
结果片段的代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f0f0f0"
tools:context="com.example.wikipicsearch.MainActivity" >
<GridView
android:id="@+id/gridView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:columnWidth="100dp"
android:gravity="center"
android:numColumns="auto_fit"
android:verticalSpacing="5dp"
android:drawSelectorOnTop="true"
android:stretchMode="columnWidth" >
</GridView>
</RelativeLayout>
我传递给自定义适配器的布局代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp"
android:clickable="true"
android:background="@drawable/grid_color_selector"
android:focusable="true">
<ImageView
android:id="@+id/image"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_margin="0dp"
android:layout_gravity="center" >
</ImageView>
</LinearLayout>
现在,我不知道为什么每个线性布局之间没有水平间距。我尝试使用android:layout_marginLeft 等等等等......根本没有任何效果!我让网格视图的片段看起来是灰色的,这样网格中的每个元素都会留下一些间距,看起来应该不错。这个你能帮我吗。蒂亚!
【问题讨论】:
-
您是否尝试在 GridView 的 xml 中设置 android:horizontalSpacing="5dp"?
-
试试这个..,添加水平间距.... android:horizontalSpacing="10dp"
-
还为您的 LinearLayout 添加背景颜色,这样当您进入此屏幕时,它会显示项目覆盖了多少空间,然后您可以相应地添加/删除边距和填充。
-
你在开玩笑吧!!!天啊!我不知道为什么当我尝试之前它没有给我一个选项来做那个(ctrl +空格自动完成帮助)....哦,伙计..我浪费了一天!非常感谢,对帽子感到抱歉,我完全……你知道吗。 :(
标签: android android-layout gridview imageview android-ui