1. 程式人生 > >android data binding jetpack VIIII 第一坑

android data binding jetpack VIIII 第一坑

column int gin columns str out scaletype linear 解決

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

android data binding jetpack VIIII 第一坑