我不太擅长编码,但是当涉及到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>
最佳答案
用 line 代替怎么样? :
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:top="-5dp" android:right="-5dp" android:left="-5dp">
<shape>
<stroke android:color="@android:color/transparent" />
<stroke
android:width=".8dp"
android:color="@color/black" />
</shape>
</item>
上面的分隔线用于垂直分隔线,这个分隔线用于水平分隔线:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:top="-5dp" android:bottom="-5dp" android:left="-5dp">
<shape>
<stroke android:color="@android:color/transparent" />
<stroke
android:width=".8dp"
android:color="@color/company_color" />
</shape>
</item>
</layer-list>
尝试使用您自己的宽度。
或从当前分隔线中删除此行android:centerColor="#000"
关于android - 如何显示水平和垂直渐变分隔线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44562214/