Android 毕加索加载图像后,我的布局崩溃
我试图构建一个定制的图像布局,如下所示,其中4个Android 毕加索加载图像后,我的布局崩溃,android,android-layout,imageview,picasso,Android,Android Layout,Imageview,Picasso,我试图构建一个定制的图像布局,如下所示,其中4个a表示一个ImageView AABC AADE 当我尝试使用默认的src属性绘制布局时,或者在毕加索上放置占位符选项时,布局渲染没有问题。然而,当毕加索逐渐懒散地加载每幅图像时,布局就这样崩溃了。(AA下面的空格为空白。) 如何使用毕加索的惰性加载保持我的原始布局?是一个自定义类,它扩展了ImageView以绘制方形ImageView PartOfLayout.xml 更新 作者使用.fit().centerCrop()和占位符的答案有效地解决
a
表示一个ImageView
AABC
AADE
当我尝试使用默认的src
属性绘制布局时,或者在毕加索上放置占位符
选项时,布局渲染没有问题。然而,当毕加索逐渐懒散地加载每幅图像时,布局就这样崩溃了。(AA
下面的空格为空白。)
如何使用毕加索的惰性加载保持我的原始布局?是一个自定义类,它扩展了ImageView
以绘制方形ImageView
PartOfLayout.xml
更新
作者使用.fit().centerCrop()
和占位符的答案有效地解决了“最终”问题,但在毕加索加载图像的过程中,布局会暂时崩溃,因为每个图像的大小不同。(成功加载所有图像后,布局看起来不错。)
如何加载图像而不破坏中间的布局?我希望加载的图像不会干扰布局,而是直接插入到具有centerCrop
状态的布局中。因为我使用LinearLayout
s作为图像帧,所以我所要做的就是将LinearLayout
的layou width
设置为match\u parent
,不像Android Studio建议的那样wrap_内容
或0dp
我的新XML如下所示
NewPartOfLayout.xml
尝试使用resize()并修复图像的大小…@NAVdroid这可以完成任务,但我以不同的方式解决了(实际上修复了我的错误)。
ABC
DE
<LinearLayout
android:id="@+id/set_profile_profile_photos_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal">
<CustomSquareImageView
android:id="@+id/set_profile_profile_photos_first"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:src="@drawable/profile" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<CustomSquareImageView
android:id="@+id/set_profile_profile_photos_second"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scaleType="centerCrop"
android:src="@drawable/profile" />
<CustomSquareImageView
android:id="@+id/set_profile_profile_photos_third"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scaleType="centerCrop"
android:src="@drawable/profile" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<CustomSquareImageView
android:id="@+id/set_profile_profile_photos_fourth"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scaleType="centerCrop"
android:src="@drawable/profile" />
<CustomSquareImageView
android:id="@+id/set_profile_profile_photos_fifth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scaleType="centerCrop"
android:src="@drawable/profile" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
try {
JSONArray profilePhotos = new JSONArray(mProfile.getProfileImages());
if (!profilePhotos.get(0).toString().isEmpty()) {
Picasso.with(getActivity()).load(profilePhotos.get(0).toString()).
placeholder(R.drawable.profile).into(mProfilePhotoFirst);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
<LinearLayout
android:id="@+id/set_profile_profile_photos_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal">
<CustomSquareImageView
android:id="@+id/set_profile_profile_photos_first"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:src="@drawable/profile" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<CustomSquareImageView
android:id="@+id/set_profile_profile_photos_second"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scaleType="centerCrop"
android:src="@drawable/profile" />
<CustomSquareImageView
android:id="@+id/set_profile_profile_photos_third"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scaleType="centerCrop"
android:src="@drawable/profile" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<CustomSquareImageView
android:id="@+id/set_profile_profile_photos_fourth"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scaleType="centerCrop"
android:src="@drawable/profile" />
<CustomSquareImageView
android:id="@+id/set_profile_profile_photos_fifth"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scaleType="centerCrop"
android:src="@drawable/profile" />
</LinearLayout>
</LinearLayout>
</LinearLayout>