我有下面的xml。我想要使图像视图可点击。但是,我似乎只能单击checkedTextView。有没有一种方法可以让我可以独立地点击检查文本视图和图像视图?看起来,checkedTextView正在消耗整个空间,而检查文本视图后面的图像视图(可能?)。有什么想法吗?对于android开发来说,这是非常新的,而且这是非常混乱的。我试着举重,但这似乎一点帮助都没有。
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="60dp"
android:orientation="vertical">
<CheckedTextView
android:id="@+id/checked_text_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
android:gravity="center_vertical"
android:text="@string/hello_world"
android:textColor="@color/white"
android:padding="20dp"
android:textSize="20sp"
android:textStyle="bold"/>
<ImageView
android:id="@+id/my_image_pencil"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/image_pencil" />
</LinearLayout>发布于 2014-01-24 04:58:42
用这个..。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="60dp" >
<CheckedTextView
android:id="@+id/checked_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
android:gravity="center|right"
android:padding="20dp"
android:text="Hello"
android:textColor="#fff"
android:textSize="20sp"
android:textStyle="bold" />
<ImageView
android:id="@+id/my_image_pencil"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="16dp"
android:src="@drawable/ic_launcher" />
</RelativeLayout>如果要在行项中单击ImageView事件,则设置
android:focusable="false为了你的CheckedTextView.
发布于 2014-01-24 04:47:26
尝尝这个,
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="60dp"
android:orientation="vertical">
<CheckedTextView
android:id="@+id/checked_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
android:gravity="center_vertical"
android:text="@string/hello_world"
android:textColor="@color/white"
android:padding="20dp"
android:textSize="20sp"
android:textStyle="bold"/>
<ImageView
android:id="@+id/my_image_pencil"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onclick="onImageClick"
android:src="@drawable/image_pencil" />
</LinearLayout>在活动中有这样一种方法
public void onImageClick(View view)
{
// handler for imageclick
}发布于 2014-01-24 05:07:39
就像在列表视图中使用复选框、按钮、图像按钮等一样。它获取listview的所有焦点,因此,当我们单击listview或列表视图的其他元素(如图像等)时,就不会对这些小部件有任何关注,因此不会对它们执行可单击的操作。
因此,只需更改复选框的代码,如下所示。
<CheckedTextView
android:id="@+id/checked_text_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
android:gravity="center_vertical"
android:text="@string/hello_world"
android:padding="20dp"
android:textSize="20sp"
android:focusable="false"
android:textStyle="bold"/>我刚在你的代码中加上了这一行..。android:focusable="false
https://stackoverflow.com/questions/21324547
复制相似问题