TextView带背景图片和自定义边框,效果如下图:
页面xml:
<android.support.constraint.ConstraintLayout 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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/white">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/icon_main_title"
app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tv_course"
android:background="@drawable/item_main"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/tv_label"
app:layout_constraintVertical_bias="0.7"/>
</android.support.constraint.ConstraintLayout>
app:layout_constraintVertical_bias="0.7"是TextView位于上下比0.7的位置。
item_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="@color/white"/>
<stroke
android:color="@color/itemColor"
android:width="1dp"/>
<padding
android:top="@dimen/normal_match_20"
android:bottom="@dimen/normal_match_20"
android:left="@dimen/normal_match_10"
android:right="@dimen/normal_match_10"/>
<corners android:radius="@dimen/normal_corner_radius"/>
</shape>
</item>
<item>
<bitmap android:src="@drawable/ic_launcher"/>
</item>
</layer-list>