【发布时间】:2017-11-17 15:14:59
【问题描述】:
我不太擅长编码,但在 android 中设计部分时,我总是做不出来。渐变颜色适用于垂直但不适用于水平。任何人都可以建议我如何将水平线上的分隔线像垂直一样放在整个项目上?
我的divider.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:angle="0"
android:endColor="@android:color/white"
android:centerColor="#000"
android:startColor="@android:color/white"
android:type="linear" />
</shape>
设计.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.thebrogrammers.design.MainActivity"
tools:showIn="@layout/app_bar_main"
android:background="@color/grey">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:clickable="true"
android:focusable="true"
android:elevation="4dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_weight="1"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1"
>
<ImageView
android:id="@+id/image1"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_marginTop="15dp"
android:layout_gravity="center"
android:src="@mipmap/ic_launcher"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Apply For Icard"
android:layout_marginBottom="15dp"
android:id="@+id/textView15"
android:textColor="@color/colorPrimaryDark"
android:textAlignment="center"
android:textStyle="bold"
/>
</LinearLayout>
<ImageView
android:layout_width="1dp"
android:layout_height="match_parent"
android:src="@drawable/divider2"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1"
>
<ImageView
android:id="@+id/image1"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_marginTop="15dp"
android:layout_gravity="center"
android:src="@mipmap/ic_launcher"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:textAppearance="?
android:attr/textAppearanceSmall"
android:text="Apply For Icard"
android:layout_marginBottom="15dp"
android:id="@+id/textView15"
android:textColor="@color/colorPrimaryDark"
android:textAlignment="center"
android:textStyle="bold"
/>
</LinearLayout>
</LinearLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="1dp"
android:src="@drawable/divider"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1"
>
<ImageView
android:id="@+id/image1"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_marginTop="15dp"
android:layout_gravity="center"
android:src="@mipmap/ic_launcher"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:textAppearance="?
android:attr/textAppearanceSmall"
android:text="Apply For Icard"
android:layout_marginBottom="10dp"
android:id="@+id/textView15"
android:textColor="@color/colorPrimaryDark"
android:textAlignment="center"
android:textStyle="bold"
/>
</LinearLayout>
<ImageView
android:layout_width="1dp"
android:layout_height="match_parent"
android:src="@drawable/divider2"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1">
<ImageView
android:id="@+id/image1"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_marginTop="15dp"
android:layout_gravity="center"
android:src="@mipmap/ic_launcher"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:textAppearance="?
android:attr/textAppearanceSmall"
android:text="Apply For Icard"
android:layout_marginBottom="10dp"
android:id="@+id/textView15"
android:textColor="@color/colorPrimaryDark"
android:textAlignment="center"
android:textStyle="bold"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
【问题讨论】:
-
与 recyclerview ?.您可以通过扩展
RecyclerView.ItemDecoration来使用自定义网格项装饰 -
我以前从不使用gridview! :|
-
哦,好的。只需 google,如果您使用 recyclerview,您应该会获得各种物品装饰器。
标签: android xml layout divider