自定义控件+下拉选择框实现
当系统自带的控件不能满足我们的需求,而我们又会经常使用到,这个时候我们就可以自定义控件。下拉框是我们在做项目中经常会需要用到的。
上图就是一个自定义的控件
点击显示下拉框进行选择:
pop_view.xml:
(自定义控件界面)
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/pop_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:layout_marginLeft="15dp"
android:paddingTop="26dp"
android:paddingBottom="10dp"
android:textColor="#000000" />
<RelativeLayout
android:id="@+id/pop_rl"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/pop_choose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="请选择"
android:textColor="#FF888888"
android:paddingTop="26dp"
android:paddingBottom="10dp"
android:paddingRight="25dp"
android:layout_toLeftOf="@+id/pop_img"
android:textSize="16sp" />
<ImageView
android:id="@+id/pop_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tint="#FFC7C7CC"
android:src="@drawable/choose"
android:layout_marginRight="15dp"
android:layout_alignParentRight="true"
android:paddingTop="26dp"
android:paddingBottom="10dp"
android:layout_centerVertical="true" />
</RelativeLayout>
</LinearLayout>
activity_main.xml:
(在布局中应用改控件)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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