回答
另一种选择是创建一个自定义LinearLayout
,其中包含四个ImageViews
xml,并可以动态重新组织使用权重显示多少个ImageViews
。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="100dp"
android:layout_height="100dp">
<LinearLayout
android:id="@+id/left_container"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_width="50dp"
android:layout_height="100dp"
android:orientation="vertical">
<ImageView
android:id="@+id/top_left_image"
android:layout_width="50dp"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#111" />
<ImageView
android:id="@+id/bottom_left_image"
android:layout_width="50dp"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#333" />
</LinearLayout>
<LinearLayout
android:id="@+id/right_container"
android:layout_width="50dp"
android:layout_height="100dp"
android:layout_toRightOf="@+id/left_container"
android:orientation="vertical">
<ImageView
android:id="@+id/top_right_image"
android:layout_width="50dp"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#555" />
<ImageView
android:id="@+id/bottom_right_image"
android:layout_width="50dp"
android:layout_height="0dp"
android:layout_weight="0"
android:background="#777" />
</LinearLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/transparent_circle_image"/>
</RelativeLayout>
你提到,你是从URL中加载图像,所以如果你使用这种方法,你将能够使用图书馆像Picasso加载图片,你就不必担心等待所有图片在绘制圆形图像之前下载。如果你这样做,每个图像可以独立于其他图像加载。
唯一的缺点是您将不得不使用具有透明圆形背景的图像来创建圆形图像的外观。你可以创建一个常用的drawable来使用。或者您可以尝试将其绘制到画布上。这questions有一个很好的解决方案,将创建一个自定义视图,绘制一个透明的圆圈。
如果您想使用的自定义视图只需更换
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/transparent_circle_image"/>
与
<com.app.view.TransparentCircle
android:layout_width="match_parent"
android:layout_height="match_parent"/>
喜欢它!最后一个问题 - 我应该如何最有效地创建具有透明圆形背景的图像? –
我刚刚更新了我的答案,并提供了一个链接,指向另一个为透明圆实现自定义视图的问题。要么使用它,要么只是创建一个正常的图像来使用。 –
没问题,祝你好运! –
有几个很好的第三部分库,你可以使用这个创建圆形图像。但事先您需要将多个图像组合成一个矩形,然后可以制作成圆形。
我会看看CircleImageView或RoundedImageView。区别在于他们的名字描述CircleImageView
会给你一个完美的圆形图像。 RoundedImageView
实际上可以提供矩形,椭圆形或圆形的圆角。
如果您试图让您的应用轻量化并避免使用外部库,那么您也可以在中间创建一个圆形图像,并在中间使用常规图像叠加为源图像顶部的背景图像ImageView
。
我可以在CircleImageView库中放置多个图像吗?它似乎没有支持,但尚未 –
@AnkitGoyal不使用任何外部库:只是看看它是如何完成在'android.support.v4.graphics.drawable.RoundedBitmapDrawable' – pskink
刚编辑我的答案,你会想要首先将图像组合成矩形。然后使用其中一个库。 –
- 1. 如何使用圆角和两个文字视图创建自定义视图?
- 2. 创建一个圆角视图
- 3. Android - 如何创建一个带圆角和平铺图像背景的视图?
- 4. 如何使用排球库创建圆角图像android
- 5. 如何使用图像创建背景,无边框圆角
- 6. 如何在C#中使用圆角创建图像?
- 7. 如何创建圆形图库视图/图像切换器/图像视图...?
- 8. 如何在Android中创建圆角地图视图?
- 9. 如何创建一个圆角的图像边框?
- 10. 如何用透明边框和圆角创建Flex图像?
- 11. 如何用Java中的圆角创建图像?
- 12. 如何使用FFMpeg从多个图像序列创建视频?
- 13. 圆角图像
- 14. 如何用多个表创建视图?
- 15. 如何在同一视角创建多个eclipse视图..?
- 16. 如何按角色为不同用户创建多个视图?
- 17. 试图创建一个圆角UIButton类
- 18. 如何使用多个动态字段创建“创建视图”?
- 19. 如何为移动网页视图创建圆角
- 20. 如何创建圆形图像包装
- 21. 如何创建图像效果和Imageview在Android的圆角
- 22. 如何创建多个图像视图设计?
- 23. 使用其他图像视图标签创建图像视图
- 24. 如何使用php和html在缩略图上创建圆角?
- 25. 如何使用Raphael画布库创建多个图层图像?
- 26. Javascript圆角图像
- 27. 图像的圆角
- 28. 如何创建可用于多个视图的视图?
- 29. SQL - 使用多个CTE创建视图
- 30. 使用多个表创建视图?
使用习惯'Drawable'其中提请4或2'Bitmap's在'draw'方法 – pskink
@ pskink我该怎么做呢?有没有可以指引我的导游?谢谢! –
是的,看到'android.support.v4.graphics.drawable.RoundedBitmapDrawable'的来源 – pskink