【发布时间】:2016-03-09 11:40:53
【问题描述】:
如何为 GridView 设置自定义分隔线?
我的意思是,有一个带有蓝色渐变分隔线的 .png 项目,但是如何将它放在 GridView 中的正确位置?
通过互联网搜索并没有带来任何可行的结果..
期待:
现实:
gridview 包装器 xml:
<LinearLayout 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="@color/primary_blue_dark"
android:orientation="vertical">
....
<GridView
android:id="@+id/gv_stock"
android:paddingEnd="@dimen/activity_horizontal_margin"
android:paddingStart="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchMode="columnWidth"
android:numColumns="2"/>
</LinearLayout>
gridview 项目 xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/primary_blue_dark"
style="@style/padded_layout"
android:weightSum="2">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_weight="1">
<TextView
android:id="@+id/tv_title"
android:layout_width="match_parent"
android:layout_height="match_parent"
style="@style/teal_text_middle"
android:gravity="center"
android:text="test"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_weight="1"
android:gravity="center">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="2">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.7"/>
<ImageView
android:id="@+id/iv_arrow"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:layout_weight="1.3"
android:src="@drawable/ic_arrow_green"/>
</LinearLayout>
<TextView
android:id="@+id/tv_value"
android:layout_width="wrap_content"
android:layout_height="match_parent"
style="@style/white_text_big"
android:gravity="center"
android:text="test"/>
</LinearLayout>
</LinearLayout>
【问题讨论】:
-
@BobMalooga,你的意思是这样吗?
android:background="@drawable/ic_separator_horizontal"。这适用于水平渐变线。但是如何在列项之间插入这样的内容?渐变应该只延伸到一行。 -
是的,我明白了。但这是一种解决方法。这将很难创建恰好位于每行中间的渐变。我的意思是它不适合所有屏幕尺寸。
-
@BobMalooga,如果您以这种解决问题的方式发布答案,我将不胜感激。因为我真的不知道如何使用这两个较小的渐变
标签: android gridview android-gridview divider