随笔 - 262  文章 - 0  评论 - 5  阅读 - 20万

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 功能一致。

 

posted on   wp7ers  阅读(114)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示