如何使图像更容易点击?
问题描述:
我在右侧的每个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
任何一个?任何帮助?
答
Twitter图像是否有可能比三角形的圆大?尝试用较大的透明背景填充图像。
答
编辑:这是一个老问题,但我正在清理我的答案。我不确定创建透明图像(或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);
不,实际上我直接利用来自Twitter的图像(我解压的APK,并获得图像),它是完全一样的大,因为它看起来,我不知道他们是否已经使ImageView的长度充满了父项,所以【ImageView】比它里面的【image】更大,通过我尝试过但仍然不知道该怎么做。 – DiveInto 2010-08-13 06:29:37