2011-05-12 83 views
1

我試圖複製蘋果的應用程序圖標的佈局。我在使用<merge><include>時遇到問題,因爲它在運行時似乎不會顯示在應用中。圖標佈局幫助

Icon

這裏的合併部分:

<Button android:id="@+id/deleteContact" 
     android:text="X" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"/> 

<TextView android:id="@+id/personName" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:gravity="bottom|right" 
      android:layout_gravity="bottom|right" 
      android:textSize="20sp" 
      android:text="asdfasdf"/> 

<ImageView android:id="@+id/personImage" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:src="@drawable/icon"/>  

</merge> 

的包括是在這裏:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:orientation="vertical" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"> 

<include layout="@layout/icon"/> 

</LinearLayout> 

我把那些在GridView這裏:

<?xml version="1.0" encoding="utf-8"?> 
<GridView xmlns:android="http://schemas.android.com/apk/res/android" 
       android:id="@+id/contactsGrid" 
       android:layout_width="fill_parent" 
       android:layout_weight="1" 
       android:layout_height="fill_parent" 
       android:numColumns="3" 
       android:horizontalSpacing="3dip" 
       android:verticalSpacing="3dip" /> 

我們設法使用relativelayouts合併圖像和文本,但是當我們添加刪除按鈕時,整個圖標本身不能再被點擊。

回答

0

它看起來像你正在複雜的事情超過他們可能需要的。嘗試使用RelativeLayout作爲按鈕,文本和圖像視圖的父視圖。例如,看看以下內容:

​​

實際上,您應該只能在GridView中使用它。你可能想用一個使用實際圖像的ImageButton代替Button。

+0

謝謝,但現在的問題是,我不能點擊圖標本身。我只能點擊裏面的按鈕。 – louieansonng 2011-05-12 05:45:28

+0

如果使用ListAdapter提供項目,則可以將onItemClickListener設置爲GridView。這將允許您獲得整個項目的點擊,而不僅僅是子視圖。 – David 2011-05-12 13:34:55