Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 可点击和聚焦的相对布局_Android_Xml_Nested - Fatal编程技术网

Android 可点击和聚焦的相对布局

Android 可点击和聚焦的相对布局,android,xml,nested,Android,Xml,Nested,它可能是重复的,我搜索了答案,但不幸的是我没有找到答案。。 我有一个相对布局,它与表行、图像视图和文本视图嵌套 <!-- add photo image --> <RelativeLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_margin="5dp" android:layout_weight="1.5" an

它可能是重复的,我搜索了答案,但不幸的是我没有找到答案。。 我有一个相对布局,它与表行、图像视图和文本视图嵌套

<!--  add photo image  -->
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_margin="5dp"
    android:layout_weight="1.5"
    android:id="@+id/layot_attach"
    android:clickable="true"
    android:focusable="true"
    android:background="@drawable/photo_button_selector"
    android:layoutDirection="rtl">



    <TableRow
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ImageView
            android:id="@+id/ic_add_photo_image"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:padding="5dp"
            android:focusable="false"
            android:clickable="false"
            android:src="@drawable/ic_attach_file_white_48dp"
            />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center_horizontal|center_vertical"
            android:textColor="@color/white"
            android:id="@+id/textView_attach"
            style="@style/title"
            android:padding="5dp"
            android:layout_weight="1" />


        <ImageView
            android:id="@+id/preview"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:padding="5dp" />
    </TableRow>
</RelativeLayout>
编辑

我没有按我想要的方式解决这个问题

我在代码中声明了我的图像图标,并将Alisenr附加到它。。我失去了点击按钮的效果。。但是现在就可以了

试试下面的解决方案在
相对布局中添加下面的属性
:-

android:background="?android:attr/selectableItemBackground"

我想你需要像这样, 布局的完整部分可单击或其他元素,请尝试此操作

具有以下属性的父布局(相对布局):-

android:descendantFocusability="blocksDescendants"

在活动的相对布局上设置
OnClickListener
。访问ID为的RelativeLayout。参考此链接-可能重复@Onkarne我确实添加了监听器ass,如您所见,我只是没有在此处发布单击方法!!在布局文件中,您正在设置android:Layout\u height=“0dp”。将
0dp
替换为
wrap\u内容
。另外,
android:layout\u weight=“1.5”
属性仅适用于线性布局。所以,不要用
layout\u weight
作为相对物。嗨,你试过了吗?他们还有什么问题吗?
android:background="?android:attr/selectableItemBackground"
android:descendantFocusability="blocksDescendants"