gpt4 book ai didi

Android 背景选择器对其 View 外的触摸使用react

转载 作者:行者123 更新时间:2023-11-30 03:10:07 24 4
gpt4 key购买 nike

我有以下布局来在屏幕上均匀缩放 4 个 View :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >

<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >

<include
android:id="@+id/one"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
layout="@layout/item" />

<include
android:id="@+id/two"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
layout="@layout/item" />
</LinearLayout>

<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >

<include
android:id="@+id/three"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
layout="@layout/item" />

<include
android:id="@+id/four"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
layout="@layout/item" />
</LinearLayout>

</LinearLayout>

在包含中使用的 item.xml 看起来像:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp" >

<RelativeLayout
android:id="@+id/bg_layout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="@drawable/bg_selector" >

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_margin="8dp"
android:ellipsize="end"
android:padding="4dp"
android:singleLine="true"
android:text="Headline"
android:textAppearance="@style/SmallTextBold"
android:textColor="#ffffff" />
</RelativeLayout>

</RelativeLayout>

结果看起来是这样的,这是我所期望的:

enter image description here

问题是,当我触摸其中一个项目/ View 时,所有背景都会改变,它们都会对触摸一个项目/ View 使用react:

enter image description here

这可能是什么问题?跟include有关系吗?

编辑:我刚刚更换了 <include> s 与包含的实际内容 item.xml布局并为这些布局提供了唯一的 ID,但问题仍然存在。

EDIT2:我多次清理我的项目,但无济于事。我继续摆弄布局,但无济于事。通过 GIT 将所有内容重置为我开始使用的内容,现在可以正常工作了。很奇怪。

最佳答案

您代码中的点击管理器可能指向您包含的每个项目的相同 ID。

尽量不要使用包含或编写您自己的自定义 View 。

关于Android 背景选择器对其 View 外的触摸使用react,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21115577/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com