bg.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">//设置背景的形状,此处为圆。
<corners android:radius="10dp"/>
//<solid android:color="#888"/>//设置图形填充色
<stroke android:color="#000" android:width="2dp"/>//stroke设置边框的颜色,宽度
<gradient android:type="linear"//设置背景渐变色
android:startColor="#0f0"
android:endColor="#00f"
android:centerColor="#fff"
android:angle="135"/>
<size android:width="100dp" android:height="100dp"/>//设置圆的半径
<padding android:bottom="10dp"//设置背景的内边距
android:top="10dp"
android:left="10dp"
android:right="10dp"/>
</shape>
bg_1.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<corners android:radius="10dp"/>
<solid android:color="#888"/>
<stroke android:color="#000" android:width="2dp"/>
<gradient android:type="linear"
android:startColor="#0f0"
android:endColor="#f00"
android:centerColor="#fff"
android:angle="135"/>
<size android:width="100dp" android:height="100dp"/>
<padding android:bottom="10dp"
android:top="10dp"
android:left="10dp"
android:right="10dp"/>
</shape>
sel.xml:设置背景选择器
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/bg_1"/>//将bg_1.xml文件放入选择器,其中state_pressed表示被按下为true加载背景文件
<item android:drawable="@drawable/bg"/>//没被按下是bg.xml背景,item不能互换。
</selector>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
tools:context="com.example.wwj_fly.image.MainActivity">
<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center"
android:tint="#88fff000"
android:src="@mipmap/ic_launcher"//
android:scaleType="center"//缩放类型
android:adjustViewBounds="true"//当imageview控件的宽度或高度一个是定值,一个是不定值。用它实现等比例缩放图片
android:tintMode="multiply"
style="?attr/buttonStyle"//将imageview设置为按钮类型,并设置focusable为true
android:focusable="true"
android:clickable="true"//可以被点击的
android:background="@drawable/sel"//将选择器sel.xml设置为该控件的背景
/>
</FrameLayout>