【Android】解决在RelativeLayout中使用ImageView, adjustViewBounds 无效
来源:互联网 发布:sql server count 慢 编辑:程序博客网 时间:2024/05/21 06:35
今天在布局时使用ImageView, 想要的效果是高度一定, 宽度随着高度的变化自动变化,保证ImageView和图片的宽高比一致,于是自然想到了adjustViewBounds属性。结果使用出来,没有达到想要的显示效果。经过验证, 发现是因为ImageView直接被RelativeLayout包裹的缘故。
几次验证的现象分别如下。
在RelativeLayout中
- layout_height设定一个定值如100dp, layout_width设为wrap_content, adjustViewBounds设为true, 无效,无论高度如何调整,宽度依然保持不变,为wrap_content
- 反过来,layout_width设定定值,layout_height设为wrap_content, 则设置adjustViewBounds为true,生效,高度会随宽度变化。
在LinearLayout中
无论是定高, 然后宽度wrap_content, 或者是反过来, 全部生效。
解决办法
在RelativeLayout中使用ImageView, 若要adjustViewBounds生效,可以在ImageView外面包裹一层LinearLayout。
说明(关于maxWidth, maxHeight)
- 以上的验证中,无论adjustViewBounds生效还是未生效, 都没有设置maxHeight或者maxWidth,这与网上普遍流传的 adjustViewBounds 必须和maxWidth或者maxHeight配合使用 才能生效的结论不符。
- 而且maxHeight或者maxWidth有其自己的含义,随便拿来用,只怕与本来的设计思路不符。
- 同时, 我在Android官方文档中也没有看到 必须使用maxWidth or minHeight的说法。
资料来源:https://developer.android.com/reference/android/widget/ImageView.html#attr_android:adjustViewBounds
(since Level 1)
求教
为什么出现这种情况,我现在没有明确的答案, 如果你知道, 或者有自己的见解, 希望不吝赐教。谢谢~
2 0
- 【Android】解决在RelativeLayout中使用ImageView, adjustViewBounds 无效
- ImageView中android:adjustViewBounds属性
- ImageView中android:adjustViewBounds属性
- ImageView中android:adjustViewBounds属性
- 解决android:layout_marginBottom在RelativeLayout中无效的问题
- 解决android:layout_marginBottom在RelativeLayout中无效的bug
- 解决android:layout_marginBottom在RelativeLayout中无效的问题
- android imageview adjustViewBounds
- android中ImageView的adjustViewBounds属性的作用
- ImageView的android:adjustViewBounds属性
- ImageView的android:adjustViewBounds属性
- ImageView的android:adjustViewBounds属性
- ImageView的android:adjustViewBounds属性
- 解决relativelayout下android:marginbottom无效
- android ImageView android:adjustViewBounds属性的作用。
- android ImageView android:adjustViewBounds属性的作用
- RelativeLayout 中android:layout_toRightOf无效原因
- 用RelativeLayout布局可以在imageview中写上文字
- 对象创建,对象方法
- action
- poj3468(A simple Problem with Integers)(线段树成段增减)
- pl/sql 块和结构
- 94. Binary Tree Inorder Traversal
- 【Android】解决在RelativeLayout中使用ImageView, adjustViewBounds 无效
- 团体程序设计天梯赛L2-004 这是二叉搜索树吗?(数据结构)
- Light OJ 1007 Mathematically Hard [欧拉函数+前缀和]【数论】
- Matlab在图片上画个半圆和矩形
- C++中enum的使用
- WAL机制
- 如何将导航栏始终固定在窗口顶部:
- C++多线程系列(一)CreateThread和_beginthreadex区别
- 写博客的一点小心得