3

我在右侧的每个 ListView 项中放置了一个图像,在布局 xml 中,我将其宽度和长度设置为 20dip ,有点小,我发现很难点击它,因为图像只占用 20*20 dip ,我希望它的长度不会改变,而它的高度完全填满了父母,我试过了:

    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>

如果你仔细观察了安卓的twitter客户端,你会发现每个ListView Item右侧的图片都非常容易点击(即使你没有点击图片,例如在按钮顶部)。我想知道该怎么做。

推特图片 http://www.freeimagehosting.net/uploads/889d10c435.png

任何人?有什么帮助吗?

4

2 回答 2

1

推特图片是否可能实际上比带有三角形的圆圈大?尝试用更大的透明背景填充图像。

于 2010-08-12T14:58:12.073 回答
0

编辑:这是一个老问题,但我仍在清理我的答案。我不确定创建透明图像(或 UI 元素)是这里的最佳解决方案,但这似乎是一个合理的解决方案。

这个问题与创建透明 ListView (如何在 Android 中使 Listview 透明)有关。答案建议编辑 styles.xml 文件以包含以下代码行中的内容(取自 Jacky 的答案)。

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

同样,这篇文章涵盖了实现透明活动(如何在 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:使图像不透明/透明)。接受的答案建议使用以下代码来绘制透明形状:

Bitmap buffer = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444);
buffer.eraseColor(Color.TRANSPARENT);
于 2010-08-12T15:22:35.947 回答