2011-03-15 60 views
2

我是一名Android編程初學者,剛開始玩android。Android:在線性佈局中點擊效果

我有一個包含2個textview的線性佈局。當我點擊linearlayout時,一個textview中的textcolor和另一個textview中的背景必須改變一小段時間。點擊後它應該返回到原始文本顏色和背景。

問題是setOnClickListener()必須在linearlayout上實現。

這是代碼

      <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"     
      android:id="@+id/linearlayout_logout" 
      android:orientation="horizontal"> 

      <TextView 
      android:gravity="center" 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:background="@drawable/logout_home_icon" /> 

      <TextView 
       android:id="@+id/text_logout" 
       android:layout_height="match_parent" 
       android:layout_width="wrap_content" 
       android:textColor="@color/white" 
       android:text="Log Out" 
       /> 
     </LinearLayout> 

這裏logout_home_icon是圖片(.png).. plsss幫助。

+0

那麼,這是什麼問題?你的代碼是什麼? – Nanne 2011-03-15 07:05:58

回答

2

在佈局本身和回調中實現setOnClickListener, onClick(),
您將獲得對LinearLayout的引用,使用該引用來使用getChildAt獲得ChildView(位置) 然後相應地進行更改。