Android基础知识---ImageView的状态切换
来源:互联网 发布:网络课程尔雅官网 编辑:程序博客网 时间:2024/05/18 05:19
实现ImageButton的两种状态的切换功能(按下和弹起):
1.在res-->drawable-hdpi中新建add_button_changed.xml布局文件,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:drawable="@drawable/add" />
<item android:state_pressed="true" android:drawable="@drawable/btn_follow_press" />
<item android:drawable="@drawable/add" />
</selector>
2.在activity_main.xml文件中添加该布局文件(包含按键的两种形式)
<include
android:id="@+id/header_layout"
layout="@layout/head"/>
<RelativeLayout
android:id="@+id/add_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
>
<ImageView
android:id="@+id/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/add_button_changed"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:shadowDx="0"
android:shadowDy="-1"
android:shadowRadius="0.2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/add"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp"
android:text="新建便签"
android:textSize="13dp"
android:textColor="#80808080"/>
</RelativeLayout>
3. 在MainActivity.java文件中将其实例化
add = (ImageView) findViewById(R.id.add);
add.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent(MainActivity.this, AddNew.class);
startActivity(intent);
}
});
1.在res-->drawable-hdpi中新建add_button_changed.xml布局文件,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:drawable="@drawable/add" />
<item android:state_pressed="true" android:drawable="@drawable/btn_follow_press" />
<item android:drawable="@drawable/add" />
</selector>
2.在activity_main.xml文件中添加该布局文件(包含按键的两种形式)
<include
android:id="@+id/header_layout"
layout="@layout/head"/>
<RelativeLayout
android:id="@+id/add_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
>
<ImageView
android:id="@+id/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/add_button_changed"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:shadowDx="0"
android:shadowDy="-1"
android:shadowRadius="0.2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/add"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp"
android:text="新建便签"
android:textSize="13dp"
android:textColor="#80808080"/>
</RelativeLayout>
3. 在MainActivity.java文件中将其实例化
add = (ImageView) findViewById(R.id.add);
add.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent(MainActivity.this, AddNew.class);
startActivity(intent);
}
});
0 0
- Android基础知识---ImageView的状态切换
- android sdk---ImageView的切换
- Android按钮状态的切换
- Android ImageView实现图片切换
- Android ImageView之切换图片
- Android ToggleButton:状态切换的Button
- Android ToggleButton:状态切换的Button
- android基础知识---语言切换
- 切换imageview当中的图片
- ImageView 的handler切换循环
- Android EditText 状态切换
- android 切换activity状态
- Android Activity状态切换
- Android图片切换状态
- 带有Checked状态的ImageView
- imageView 的高亮状态
- 线程基础知识-产生、退出、状态切换
- Android ImageView——图片切换
- HTTPS为什么安全 &分析 HTTPS 连接建立全过程
- leetcode解题笔记:127. Word Ladder
- JPA
- java学习总结(16.07.16)Random类和BigDecimal类
- PL/SQL Developer 如何显示行号
- Android基础知识---ImageView的状态切换
- 安装scrapy各种问题
- LeetCode - 61. Rotate List
- sql语句的优化
- 运行和控制Nginx
- JavaScript实现图片轮播和鼠标悬停显示
- android架构篇mvp+rxjava+retrofit+eventBus
- Android 设置EditText光标显示与隐藏,颜色及粗细
- 【环境配置记录】懒人 Ubuntu 2016.04 64bit 安装LNMP+Redis