首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CheckedTextView in LinearLayout

CheckedTextView in LinearLayout
EN

Stack Overflow用户
提问于 2014-01-24 04:37:36
回答 3查看 735关注 0票数 0

我有下面的xml。我想要使图像视图可点击。但是,我似乎只能单击checkedTextView。有没有一种方法可以让我可以独立地点击检查文本视图和图像视图?看起来,checkedTextView正在消耗整个空间,而检查文本视图后面的图像视图(可能?)。有什么想法吗?对于android开发来说,这是非常新的,而且这是非常混乱的。我试着举重,但这似乎一点帮助都没有。

代码语言:javascript
复制
 <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>
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2014-01-24 04:58:42

用这个..。

代码语言:javascript
复制
<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事件,则设置

代码语言:javascript
复制
android:focusable="false

为了你的CheckedTextView.

票数 1
EN

Stack Overflow用户

发布于 2014-01-24 04:47:26

尝尝这个,

代码语言:javascript
复制
   <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>

在活动中有这样一种方法

代码语言:javascript
复制
public void onImageClick(View view)
{
  // handler for imageclick
}
票数 0
EN

Stack Overflow用户

发布于 2014-01-24 05:07:39

就像在列表视图中使用复选框、按钮、图像按钮等一样。它获取listview的所有焦点,因此,当我们单击listview或列表视图的其他元素(如图像等)时,就不会对这些小部件有任何关注,因此不会对它们执行可单击的操作。

因此,只需更改复选框的代码,如下所示。

代码语言:javascript
复制
<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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21324547

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档