Android點擊Button實現(xiàn)切換點擊圖片效果的示例
這是一個簡單的小的DEMO , 關于點擊按鈕用于實現(xiàn)圖片的切換, 重要的就是里面的關于邏輯的處理, 在以后圖片輪播的技術(shù)上關于邏輯的處理和這個類似
Android Button的點擊事件切換點擊圖片
<RelativeLayout 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" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="184dp" android:background="@drawable/button_selector" /> </RelativeLayout>
android:background="@drawable/button_selector"
(2)在res文件夾下創(chuàng)建drawable文件夾,創(chuàng)建一個selector文件
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/q" android:state_pressed="true"></item> <item android:drawable="@drawable/w" android:state_focused="true"></item> <item android:drawable="@drawable/e"></item> </selector>
文件夾內(nèi)放三張圖片用于切換的時候改變圖片
(3)其他內(nèi)容不需要改變
文件的圖片隨著按鈕的點擊變化
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對腳本之家的支持。如果你想了解更多相關內(nèi)容請查看下面相關鏈接
- Android開發(fā)之使用ViewPager實現(xiàn)圖片左右滑動切換效果
- Android自定義ImageView實現(xiàn)點擊兩張圖片切換效果
- Android編程單擊圖片實現(xiàn)切換效果的方法
- Android實現(xiàn)滑動屏幕切換圖片
- Android中ViewPager組件的基本用法及實現(xiàn)圖片切換的示例
- Android實現(xiàn)圖片輪播切換實例代碼
- Android編程實現(xiàn)圖片背景漸變切換與圖層疊加效果
- Android 圖片切換器(dp、sp、px) 的單位轉(zhuǎn)換器
- Android控件ImageSwitcher實現(xiàn)左右圖片切換功能
- Android實現(xiàn)左右滑動切換圖片
相關文章
淺談Android性能優(yōu)化之內(nèi)存優(yōu)化
Android的內(nèi)存優(yōu)化是性能優(yōu)化中很重要的一部分,本文將詳細介紹Android性能優(yōu)化之內(nèi)存優(yōu)化。2021-06-06揭秘在ListView等AdapterView上動態(tài)添加刪除項的陷阱
今天遇到這么個需求,需要在運行時動態(tài)添加ListView的item,看起來很簡單,實際操作過程中卻遇到了麻煩,下面揭秘在ListView等AdapterView上動態(tài)添加刪除項的陷阱2016-04-04完美解決Android三星手機從圖庫選擇照片旋轉(zhuǎn)問題
這篇文章主要幫助大家完美解決了Android三星手機從圖庫選擇照片旋轉(zhuǎn)問題,很實用的解決小案例,感興趣的小伙伴們可以參考一下2016-04-04Android模塊化中數(shù)據(jù)傳遞/路由跳轉(zhuǎn)實現(xiàn)示例
這篇文章主要介紹了Android模塊化中數(shù)據(jù)傳遞/路由跳轉(zhuǎn)實現(xiàn)示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-07-07