自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Android UI控件組合應(yīng)用之二:按鈕布局

移動(dòng)開發(fā) Android
本文以Android版本的新浪微博手機(jī)客戶端為例,介紹了Android代碼如何實(shí)現(xiàn)微博主體列表框。作者與大家分享了如何使用ImageButton控件和RelativeLayout對按鈕進(jìn)行設(shè)置和布局。

在上一篇文章中,我們已經(jīng)完成了數(shù)據(jù)模型的代碼,并且為了測試方便,在類中直接為很多成員變量提供了默認(rèn)值。接下來,進(jìn)入到界面部分。

縱觀整個(gè)界面,可以分成上下兩塊,一塊是頂端的操作條,另一塊是占主體的列表框。

先從頂端的操作條開始,在這里,很容易分解成三個(gè)部分,左側(cè)的寫微博按鈕,中間的用戶名顯示,右側(cè)的刷新按鈕。兩個(gè)按鈕的風(fēng)格是一樣的,都是有常規(guī)和按下兩種狀態(tài),這種按鈕是非常常用的,我的做法是:

1. 在drawable文件夾下建立兩個(gè)xml文件,分別對應(yīng)了兩個(gè)按鈕;

2. 每個(gè)xml文件中使用selector標(biāo)簽定義常規(guī)狀態(tài)和選中狀態(tài)的兩個(gè)圖片資源;

3. 在Activity的布局中使用ImageButton,指定按鈕的background為透明,并指定src為剛才定義的兩個(gè)xml。

下面是這兩個(gè)xml文件的內(nèi)容:

 

  1. view plaincopy to clipboardprint?  
  2. <?xml version="1.0" encoding="utf-8"?>    
  3. <selector xmlns:android="http://schemas.android.com/apk/res/android">    
  4.     <item android:state_pressed="true" android:drawable="@drawable/title_new_selected" />    
  5.     <item android:drawable="@drawable/title_new_normal" />    
  6. </selector> 

 

 

 

  1. view plaincopy to clipboardprint?  
  2. <?xml version="1.0" encoding="utf-8"?>    
  3. <selector xmlns:android="http://schemas.android.com/apk/res/android">    
  4.     <item android:state_pressed="true" android:drawable="@drawable/title_reload_selected" />    
  5.     <item android:drawable="@drawable/title_reload_normal" />    
  6. </selector> 

 

 

在main.xml文件中,進(jìn)行這一部分的布局,對于這三個(gè)界面元素而言,有明確的位置關(guān)系,因此采用RelativeLayout合適,內(nèi)容如下:

 

  1. view plaincopy to clipboardprint?  
  2. <RelativeLayout      
  3.     android:layout_width="fill_parent" android:layout_height="44dp"    
  4.     android:background="@drawable/titlebar_lightgray_bg" android:orientation="horizontal">    
  5.     <ImageButton android:id="@+id/BtnWrite"    
  6.         android:layout_width="wrap_content" android:layout_height="fill_parent"    
  7.         android:layout_alignParentLeft="true" android:background="@android:color/transparent"    
  8.         android:src="@drawable/write_button">    
  9.     </ImageButton>    
  10.     <TextView android:id="@+id/TextViewUsername"    
  11.         android:layout_width="fill_parent" android:layout_height="fill_parent"    
  12.         android:textColor="@color/black" android:gravity="center" android:textSize="18sp">    
  13.     </TextView>    
  14.     <ImageButton android:id="@+id/BtnRefresh"    
  15.         android:layout_width="wrap_content" android:layout_height="fill_parent"    
  16.         android:layout_alignParentRight="true" android:background="@android:color/transparent"    
  17.         android:src="@drawable/refresh_button">    
  18.     </ImageButton>    
  19. </RelativeLayout> 

 

 

 

最后,指定RelativeLayout的background為背景圖片即可。

本次用到的圖片有:

               

責(zé)任編輯:佚名 來源: CSDN博客
相關(guān)推薦

2011-05-17 17:12:39

2011-03-11 10:35:31

SQL鎖定SQL Server

2011-04-11 15:57:22

DFSBFSC++

2022-02-17 20:07:45

Flex鴻蒙Flex組件

2014-01-03 13:56:00

手游用戶體驗(yàn)設(shè)計(jì)啟動(dòng)和停止

2011-08-15 10:15:00

iPhone開發(fā)警告框

2011-08-10 15:36:26

iPhone靜態(tài)庫控件

2010-05-13 15:18:19

Subversion插

2017-02-13 17:17:48

Android標(biāo)題欄控件

2011-05-30 08:58:59

Android focusable 屬性

2011-09-07 14:34:55

Android Wid控件

2011-05-30 17:02:56

Android Activity 傳參與跳轉(zhuǎn)

2009-01-13 14:49:14

Winform視頻教程控件

2013-01-08 16:05:23

Android開發(fā)布局ViewStub

2021-12-20 21:01:52

鴻蒙HarmonyOS應(yīng)用

2011-04-08 13:58:10

Android界面設(shè)計(jì)

2009-07-15 09:59:36

MyEclipse使用

2009-07-15 09:59:36

MyEclipse使用

2021-04-21 09:55:24

Redis應(yīng)用限流

2010-06-10 13:47:16

點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號