本篇文章為大家展示了如何在Android應(yīng)用中實(shí)現(xiàn)一個(gè)動(dòng)態(tài)searchview搜索欄效果,內(nèi)容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細(xì)介紹希望你能有所收獲。
實(shí)現(xiàn)這個(gè)效果, 只要關(guān)注幾個(gè)點(diǎn)
1.搜索欄伸展和收縮動(dòng)畫效果實(shí)現(xiàn)
2.搜索欄伸展和收縮的時(shí)機(jī)
3.頂部透明度的漸變
搜索欄伸展和收縮動(dòng)畫效果實(shí)現(xiàn):
我們只要明確,使用系統(tǒng)為我們提供的Transition框架,就可以輕而易舉的實(shí)現(xiàn)了。
首先要引入依賴compile 'com.android.support:design:25.3.1',要知道我們使用到的這部分Transition效果只是封裝了屬性動(dòng)畫的內(nèi)容,是可以兼容到5.0之前的。
private void expand() { //設(shè)置伸展?fàn)顟B(tài)時(shí)的布局 tvSearch.setText("搜索簡書的內(nèi)容和朋友"); RelativeLayout.LayoutParams LayoutParams = (RelativeLayout.LayoutParams) mSearchLayout.getLayoutParams(); LayoutParams.width = LayoutParams.MATCH_PARENT; LayoutParams.setMargins(dip2px(10), dip2px(10), dip2px(10), dip2px(10)); mSearchLayout.setLayoutParams(LayoutParams); //設(shè)置動(dòng)畫 beginDelayedTransition(mSearchLayout); } private void reduce() { //設(shè)置收縮狀態(tài)時(shí)的布局 tvSearch.setText("搜索"); RelativeLayout.LayoutParams LayoutParams = (RelativeLayout.LayoutParams) mSearchLayout.getLayoutParams(); LayoutParams.width = dip2px(80); LayoutParams.setMargins(dip2px(10), dip2px(10), dip2px(10), dip2px(10)); mSearchLayout.setLayoutParams(LayoutParams); //設(shè)置動(dòng)畫 beginDelayedTransition(mSearchLayout); } void beginDelayedTransition(ViewGroup view) { mSet = new AutoTransition(); //設(shè)置動(dòng)畫持續(xù)時(shí)間 mSet.setDuration(300); // 開始表演 TransitionManager.beginDelayedTransition(view, mSet); }
網(wǎng)站標(biāo)題:如何在Android應(yīng)用中實(shí)現(xiàn)一個(gè)動(dòng)態(tài)searchview搜索欄效果-創(chuàng)新互聯(lián)
網(wǎng)頁路徑:http://chinadenli.net/article18/dgpjdp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營銷、靜態(tài)網(wǎng)站、外貿(mào)建站、動(dòng)態(tài)網(wǎng)站、網(wǎng)站維護(hù)、網(wǎng)站設(shè)計(jì)公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
移動(dòng)網(wǎng)站建設(shè)知識(shí)