- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将带有 findViewByIds 的现有项目转换为 ViewBinding。 ScrollView 之外的所有 View ID 都可以在 Android Studio 中与“binding.viewId ...”一起使用。 。”因此,我无法访问布局中 ViewFlipper 内的两个
//Activity
private ActivityEditBinding binding;
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityEditBinding.inflate(getLayoutInflater());
View view = binding.getRoot();
setContentView(view);
// activity_edit.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:focusableInTouchMode="true"
tools:context=".AddorUpdateCardActivity">
...
<RelativeLayout
android:id="@+id/secondLinearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/toolbar" >
<ScrollView
android:id="@+id/ScrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/secondLinearLayout"
... >
<LinearLayout
android:id="@+id/lowerVFRow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingRight="5dp"
android:paddingEnd="5dp"
android:orientation="horizontal" >
<ViewFlipper
android:id="@+id/expandVF"
android:layout_width="wrap_content"
android:layout_height="44dp"
android:layout_marginBottom="5dp" >
<include layout="@layout/expand_more_act_edit"
android:id="@+id/expandMore" />
<include layout="@layout/expand_less_act_edit"
android:id="@+id/expandLess" />
</ViewFlipper>
</LinearLayout>
</ScrollView>
</RelativeLayout>
// expand_more_act_edit.xml
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/downArrow"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:contentDescription="sd"
android:clickable="true"
android:focusable="true"
android:src="@drawable/ic_expand_more" />
<!-- the down arrow -->
我确认自动生成的 ViewBinding 类已经创建。下面是我试图将 ClickListener 附加到 downArrow 但我无法访问 downArrow 引用的地方。我在这里缺少什么?
***Android Studio says "Cannot resolve symbol 'expandMore'***
binding.expandMore.downArrow.setOnClickListener(v -> {
// change the down arrow to the up arrow and show the 1-20 EditText lines.
expandVF.setDisplayedChild(expandVF.indexOfChild(findViewById(R.id.expandLess)));
moreViewStub.setVisibility(View.VISIBLE);
});
ViewBinding 不能在 ScrollView 中工作吗?我在这里缺少什么?
最佳答案
View binding 将从您在布局中提供的 id 生成 camelCase id。如果您的 View id 已经在布局中的 camelCase(expandVF) 中,有时 android studio 将无法识别,因为布局 View id 和绑定(bind)类 View ID 相同。这可能会产生“无法解析符号错误”。
所以不要使用 expandVF、expandMore、expandLess,而是使用 expand_vf、expand_more、expand_less。重建并运行,可能会起作用。
关于Android:ViewBinding 的 ScrollView 内没有可用的 View ID。如何访问?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67779226/
我使用包含布局,我需要更改它的可见性: 而 layout_select_provinces 是这样的: 但是当我将 Id 设置为
我尝试在Build.gradle.kts中添加*View Binding。*我无法将BuildFeature{viewBinding;true}添加到Build.gradle.kts中。kts显示一条
我现在在 kotlin 中使用 viewBinding。 这是我的build.gradle 启用 ViewBinding 并自动导入 ViewBinding 依赖。 但 Android Studio
碰巧我有一个主应用程序模块 构建.gradle dynamicFeatures = [":myFeature"] viewBinding { enabled = tru
我的风格包含与我的 main 中相同的布局资源。源集。这样它就可以用特定于 flavor 的那一种来覆盖主要的那一种。我在很多地方都这样做过,在我介绍 ViewBinding 之前效果很好。 .为了准
编辑 - 解决方案 使用 View 绑定(bind)时,会为每个 xml 生成一个 Java 绑定(bind)文件。问题是当您修改 xml 时,它不会重新生成 Java 文件。因此,当我向 activ
我需要显示一个带有一些图像的 ListView,我正在使用以下代码: dataText = (TextView)findViewById(R.id.data); dataText.se
我有一个 ViewBinder,它充当我的 ListView 和数据库游标适配器之间的中间人。根据显示此数据的上下文,我需要 ViewBinder 来执行不同的操作。 例如,以一个任务管理应用程序为例
我有一个布局复杂的列表 R.layout.menu_row。它由一个 ProgressBar 和一个文本字段组成。我使用的适配器: SimpleAdapter simpleAdapter = n
我对这个"new"Android View 绑定(bind)有疑问。当我尝试使用 时出现异常在我的 XML 布局文件中: 包含文件只是一个基本的布局文件。如果我替换 一切正常直接使用应包含的布局
如何/在哪里可以找到生成的 ViewBinding 代码? 每当我尝试 control+click/control+b 来查看声明时,AndroidStudio 只会打开 XML 布局。 最佳答案 生
将 Android Studio 更新为 后北极狐和 Android Gradle 插件到 7.0.0 我正面临这个警告,我的意思是尽管有这个警告,应用程序仍然可以成功构建,但是我在这里缺少什么?这里
我开始使用 ViewBinding。在搜索了一些示例或建议如何将 ViewBinding 与抽象基类一起使用后,该抽象基类应处理预期出现在每个子布局中的 View 的相同逻辑,我最终在此处发布了此问题
我想用自定义 View 试用 ViewBinding,例如: MainActivity layout_main.xml MyCustomView layout_my_custom_view.xml
在使用 ViewBinding 时,我遇到了一些未记录的案例。 第一:如何获得包含的通用 View 布局部分的绑定(bind),主绑定(bind)只看到主布局中的项目? 第二:如何获得包含的合并类型布
我在 build.gradle 文件中启用了 View 绑定(bind): android { ... viewBinding { enabled = true
我有一个从本地数据库中获取的项目列表。每个项目都有属性 isNew。我只想为匹配 isNew = true 的项目显示带有文本“new”的 TextView。我用两种方法解决了这个问题,现在我想知道哪
我正在使用 SimpleCursorAdapter,我不确定为什么它有时会起作用。如果我重做相同的查询,我会得到不同的绑定(bind)。虽然我知道这与光标的内容无关。 我要做的就是在 cursor.g
我已经在 android 中使用 SQlite 成功创建了一个表。数据库中有一列性别(男/女)。我想做的是检查性别类型并根据类型显示男/女图标。我使用了 setViewBinder() 来传递列索引(
我们正在使用 DataBinding自 Jetpack 发布以来。 Android 文档表明 ViewBinding在 Android Studio 3.6 Canary 11+ 中添加。 我阅读了文
我是一名优秀的程序员,十分优秀!