2010-08-12 69 views
3

我在右側的每個ListView項目中放置了一個圖像,在佈局xml中,我將它的寬度和長度設置爲20dip,類型很小,我發現很難點擊它,導致圖像只佔用20 * 20浸,我希望它的長度不變,而其高度完全填充父, 我想:如何使圖像更容易點擊?

android:layout_width="20dip" 
    android:layout_height="fill_parent" 

,但它不工作。

下面是我的xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/item" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:orientation="horizontal" 
android:padding="6dip" 
android:background="#FFFFFF"> 

<ImageView android:id="@+id/avatar" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginRight="6dip" 
    android:src="@drawable/default_happy_face" /> 

<RelativeLayout 
    android:orientation="vertical" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:layout_toRightOf="@id/avatar" 
      android:layout_toLeftOf="@+id/optionImg"> 

    <!-- some stuff unrelated--> 

</RelativeLayout> 

<!-- v Pay attention here v --> 
<ImageView android:id="@+id/optionImg" 
    android:layout_width="20dip" 
    android:layout_height="fill_parent" 
    android:layout_marginLeft="15dip" 
    android:paddingLeft="5dip" 
    android:adjustViewBounds="true" 
    android:background="@drawable/option_normal" 
    android:layout_alignParentRight="true" 
    android:layout_centerVertical="true"/> 
</RelativeLayout> 

如果你仔細觀看爲Android的Twitter客戶端,你會發現,在每個ListView項的右側的圖像是相當容易點擊(即使你有沒有點擊圖片,但是例如在按鈕上方說)。我想知道如何做到這一點。

twitter image http://www.freeimagehosting.net/uploads/889d10c435.png

任何一個?任何幫助?

回答

1

Twitter圖像是否有可能比三角形的圓大?嘗試用較大的透明背景填充圖像。

+0

不,實際上我直接利用來自Twitter的圖像(我解壓的APK,並獲得圖像),它是完全一樣的大,因爲它看起來,我不知道他們是否已經使ImageView的長度充滿了父項,所以【ImageView】比它裏面的【image】更大,通過我嘗試過但仍然不知道該怎麼做。 – DiveInto 2010-08-13 06:29:37

0

編輯:這是一個老問題,但我正在清理我的答案。我不確定創建透明圖像(或UI元素)是否是最好的解決方案,但它似乎是一個合理的解決方案。

此問題與創建透明ListView(How To Make a Listview Transparent in Android)有關。答案建議編輯styles.xml文件以包含以下代碼(取自Jacky的回答)。

android:background="@drawable/bg" 
android:cacheColorHint="#00000000" 

同樣,本文涵蓋了實施透明活動(How to Create Transparent Activity in Android)。接受的答案中的代碼如下所示。

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <style name="Theme.Transparent" parent="android:Theme"> 
    <item name="android:windowIsTranslucent">true</item> 
    <item name="android:windowBackground">@android:color/transparent</item> 
    <item name="android:windowContentOverlay">@null</item> 
    <item name="android:windowNoTitle">true</item> 
    <item name="android:windowIsFloating">true</item> 
    <item name="android:backgroundDimEnabled">false</item> 
    </style> 
</resources> 

最後,這裏的一對圖像的不透明度/透明度的Android(Android: Make image opaque/transparent)一個一般性的問題。該接受的答案建議使用下面的代碼,以吸引透明形狀:

Bitmap buffer = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444); 
buffer.eraseColor(Color.TRANSPARENT);