android data binding jetpack VIIII 第一坑

 <LinearLayout
            android:id="@+id/ll_item_home_page_pics"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/rl_item_home_page_top"
            android:layout_marginTop="10dp"
            android:orientation="horizontal">

            <ImageView
                android:id="@+id/iv_pic0"
                android:layout_width="0dp"
                android:layout_height="80dp"
                android:layout_weight="1"
                android:scaleType="fitXY"
                android:src="@drawable/tempic"
                bind:url="@{product.imgUrls.get(0)}"
                tools:ignore="ContentDescription" />

            <ImageView
                android:id="@+id/iv_pic1"
                android:layout_width="0dp"
                android:layout_height="80dp"
                android:layout_marginStart="10dp"
                android:layout_marginEnd="10dp"
                android:layout_weight="1"
                android:scaleType="fitXY"
                android:src="@drawable/tempic1"
                bind:url="@{product.imgUrls.get(1)}"
                tools:ignore="ContentDescription" />

            <ImageView
                android:id="@+id/iv_pic2"
                android:layout_width="0dp"
                android:layout_height="80dp"
                android:layout_weight="1"
                android:scaleType="fitXY"
                android:src="@drawable/tempic2"
                bind:url="@{product.imgUrls.get(2)}"
                tools:ignore="ContentDescription" />
        </LinearLayout>

如上代码,三张图片一行均分布局,LinearLayout + android:layout_weight="1" 很正常的做法。使用glide给图片绑定。

结果-->>>>>图片全出不来。

简单分析也不知道哪个环节出问题了。根本问题是图片的宽高没了。

项目紧先给个解决方案,后期再分析原因。

改用tablelayout 后正常。没到测试期,不知道其它版本系统是不是有问题。

 <TableLayout
            android:id="@+id/ll_item_home_page_pics"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/rl_item_home_page_top"
            android:layout_marginTop="10dp"
            android:orientation="horizontal"
            android:stretchColumns="*">

            <TableRow>

                <ImageView
                    android:id="@+id/iv_pic0"
                    android:layout_width="0dp"
                    android:layout_height="80dp"
                    android:scaleType="fitXY"
                    android:src="@drawable/tempic"
                    bind:url="@{product.imgUrls.get(0)}"
                    tools:ignore="ContentDescription" />

                <ImageView
                    android:id="@+id/iv_pic1"
                    android:layout_width="0dp"
                    android:layout_height="80dp"
                    android:layout_marginStart="10dp"
                    android:layout_marginEnd="10dp"
                    android:scaleType="fitXY"
                    android:src="@drawable/tempic1"
                    bind:url="@{product.imgUrls.get(1)}"
                    tools:ignore="ContentDescription" />

                <ImageView
                    android:id="@+id/iv_pic2"
                    android:layout_width="0dp"
                    android:layout_height="80dp"
                    android:scaleType="fitXY"
                    android:src="@drawable/tempic2"
                    bind:url="@{product.imgUrls.get(2)}"
                    tools:ignore="ContentDescription" />
            </TableRow>

        </TableLayout>
注意使用:android:stretchColumns="*" 基本跟android:layout_weight 功能一致。

原文地址:https://www.cnblogs.com/mamamia/p/10177846.html

时间: 2024-07-31 19:56:08

android data binding jetpack VIIII 第一坑的相关文章

android data binding jetpack V

来实现一个recyclerview绑定. 看了例子理一下思路. 第一个关系: item 与itemview 数据与展示绑定. recyclerview 更新数据和UI过程是:获取holder类型->产生holder->获取holder()->holder+data->展示. 代码在adapter中执行. 1.获取某个位置的holder类型. @Override public int getItemViewType(int position) { return super.getIt

Android Data Binding

1 引入 如何高效地实现以下界面? 有好几年findViewById实战经验的我,感觉并不难啊.一般会 * 1.先定义一个User的Model类,数据来自JSON解析: * 2.创建一个xml,随后在xml中布局完所有View,对头像.标题.积分.登录按钮一个id: * 3.在Activity中通过findViewById获取到头像ImageView.标题TextView.积分TextView.登录Button,然后给Button设置监听器,再根据登陆状态展示对应数据: 实现如下: * User

Android Data Binding 技术

Android Data Binding 技术

Android Data Binding实战(一)

在今年Google I/O大会上,Google推出Design Library库的同时也推出了Android Data Binding,那么什么是Data Binding?其名曰数据绑定,使用它我们可以轻松实现MVVM(模型-视图-视图模型)模式,来实现应用之间数据与视图的分离.视图与业务逻辑的分离.数据与业务逻辑的分离,从而达到低耦合.可重用性.易测试性等好处,那么我们首先先来看看什么是MVVM模式. 我自己画了一张图来帮助理解,就不多描述了,毕竟重点是Data Binding的使用 通过上图

Android Data Binding代码实践(告别findViewById)

Data Binding实战(一) Data Binding语法解析(二) Data Binding高级用法(三) 好了,继前三篇学习了Data Binding之后,我们可以发现它的强大之处有这么几点: 1.使用MVVM模式,让整个项目结构清晰明了 2.通过ViewModel连接View和Model,使得View与Model层解耦,分层后各司其职,维护方便 3.易于项目的测试 4.可以根据id自动生成View的对象,再也不用findViewById了 好了,说了好处,当然也有不太好的地方,毕竟是

Android Data Binding 系列(二) -- Binding与Observer实现

写在前面 上篇文章 Android Data Binding 系列(一) – 详细介绍与使用 介绍了 Data Binding 的基础及其用法,本文接上篇,结合DataBindingDemo 来学习下 Data Binding 的实现. 绑定实现 Activity在inflate layout时,通过DataBindingUtil来生成绑定,从代码看,是遍历contentView得到View数组对象,然后通过数据绑定library生成对应的Binding类,含Views.变量.listeners

Android Data Binding Library 官方文档(译)

地址:https://developer.android.google.cn/topic/libraries/data-binding/index.html 本文地址:http://blog.csdn.net/jjwwmlp456/article/details/54915981 Data Binding Library (数据绑定库),旨在减少绑定应用程序逻辑和布局所需的一些耦合性代码 最低支持Android 2.1 (API Level 7) 构建环境 使用gradle插件1.5-alpha

Android Data Binding语法解析(二)

上篇我们知道了Data Binding的最简单的用法,那么Data Binding其中最为重要也是最复杂的其实就是在xml布局文件中给对应的控件进行数据绑定了,接下来就一一说明Data Binding的使用各个场景的语法. 我们以User类这个Model为例: public class User { private String userName; private String userPassword; private boolean isExist; public String getUse

完全掌握Android Data Binding

转载:http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/0603/2992.html 来源 https://github.com/LyndonChin/MasteringAndroidDataBinding 编辑推荐:稀土掘金,这是一个针对技术开发者的一个应用,你可以在掘金上获取最新最优质的技术干货,不仅仅是Android知识.前端.后端以至于产品和设计都有涉猎,想成为全栈工程师的朋友不要错过! 本教程是跟着 Data Bind