简体   繁体   English

ListView上的可点击图像

[英]Clickable image on ListView

I want to have a ListView that have an image in every item (star) and that image is clickabe. 我想要一个在每个项目(星号)中都有一个图像且该图像是clickabe的ListView。 In other word user can click on star of every row of ListView and i want to define click action for that. 换句话说,用户可以单击ListView的每一行的星形,而我想为此定义点击动作。 How i can do this? 我该怎么做?

Add an imageView.. make it clickable by adding this to your ImageView tag: 添加一个imageView ..通过将其添加到您的ImageView标签使其可单击:

android:clickable="true"
android:focusable = "false"

it should work.. 它应该工作..

you can make a ImageButton like 你可以像这样制作一个ImageButton

   <ImageButton
          android:id="@+id/sound_button"
          android:layout_x="430px" 
          android:layout_y="219px"
          android:layout_width="48px "
          android:layout_height="48px" 
          android:scaleType="center"
          android:src="@android:drawable/volumeicon"
          android:background="@drawable/clearbuttonup"
             />

and make a new xml and name it selector 并创建一个新的xml并将其命名为选择器

           <?xml version="1.0" encoding="utf-8"?>
          <selector xmlns:android="http://schemas.android.com/apk/res/android">
             <item android:state_pressed="true"
                   android:drawable="@drawable/button_pressed" /> <!-- pressed -->
             <item android:state_focused="true"
                   android:drawable="@drawable/button_focused" /> <!-- focused -->
            <item android:drawable="@drawable/button_normal" /> <!-- default -->
            </selector>

OR you make a Imageview and setproperty of that ImageView isClickable="true" 或您制作一个Imageview以及该ImageView的setProperty isClickable =“ true”

you can use an ImageButton, 您可以使用ImageButton,

http://developer.android.com/reference/android/widget/ImageButton.html http://developer.android.com/reference/android/widget/ImageButton.html

you can also simply make the image clickable, and set it's onClickListener(), 您还可以简单地使图像可点击,并将其设置为onClickListener(),

http://developer.android.com/reference/android/view/View.html#setOnClickListener(android.view.View.OnClickListener ) http://developer.android.com/reference/android/view/View.html#setOnClickListener(android.view.View.OnClickListener

the problem with this however is that there will be no visual feedback to the user as the image is clicked. 但是,这样做的问题是在单击图像时不会向用户提供视觉反馈。 an image button looks and acts like a button, and if you are willing to provide normal, pressed, etc versions of the image, you can attach a state list drawable to the image button to make it look very professional. 图像按钮的外观和作用类似于按钮,如果您愿意提供正常,按下等版本的图像,则可以在图像按钮上附加可绘制的状态列表,以使其看起来非常专业。

http://developer.android.com/reference/android/graphics/drawable/StateListDrawable.html http://developer.android.com/reference/android/graphics/drawable/StateListDrawable.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM