Android 线性布局中的CheckedTextView

Android 线性布局中的CheckedTextView,android,xml,Android,Xml,我有下面的xml。我想让imageview可点击。但是,我似乎只能单击checkedTextView。有没有一种方法可以让checkedtextview和imageview独立单击?看起来checkedTextView占用了整个空间,而imageview位于checkedTextView后面(可能?)。有什么想法吗?对于android开发来说,这是一个相当新的概念,这一点非常混乱。我试着举重,但似乎毫无帮助 <LinearLayout xmlns:android=

我有下面的xml。我想让imageview可点击。但是,我似乎只能单击checkedTextView。有没有一种方法可以让checkedtextview和imageview独立单击?看起来checkedTextView占用了整个空间,而imageview位于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>

试试这个

   <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>
用这个

<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>

当我们在列表视图中使用复选框、按钮、图像按钮等时,为您的选中文本视图

。它占据了listview的所有焦点,因此当我们单击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

hmmm运气不好:(还是一样吗?你横向需要吗?@PiyushGupta是的,它是列表中的一行=/hmm好吧,它使列表中每一行的布局看起来更好。但是我仍然只能选择checkedTextView。谢谢你试图帮助我。仍然不走运!我不知道为什么什么都不起作用=/Thanway不走运。出于某种原因,整行仍然是空的。)被checkedtextview选中,因此这是我唯一可以选择的东西..=/无论如何,谢谢,尽管您在特定的列表项中使用imageview和checkbox,然后将android:focusable=“true”添加到imageview,可能是此时imageview上的焦点出现。此错误是由于焦点出现的。您可以尝试此操作,这可能是有效的。
android:focusable="false
<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"/>