ImageView 如何自适应屏幕?

vnking 2013-06-28 04:56:07
我的程序是两个手指一捏就将图片缩小,但是当图片被捏得太小时,让它自适应屏幕大小来显示,请问这个应该怎么做?


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

<ImageView
android:id="@+id/imageView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/example"
android:background="@drawable/background"
android:scaleType="matrix" />


</RelativeLayout>



float scale = newDist/oriDis;
matrix.postScale(scale, scale, midPoint.x, midPoint.y);
view.setImageMatrix(matrix);


怎样取得view显示的宽度和高度?
...全文
139 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
vnking 2013-06-29
  • 打赏
  • 举报
回复
引用 2 楼 lihui_shine 的回复:
view.getLayoutParams().height view.getLayoutParams().width
返回值都是 -1 啊,没有达到预期目的。 我的要求是在图片缩小时能检测到当前图片显示的位置和大小,如果过小的话自动让它适合当前屏幕的大小。
  • 打赏
  • 举报
回复
android:scaleType="fitCenter"
KPRF2009 2013-06-28
  • 打赏
  • 举报
回复
LS两位的都可以。。。
浪尖赏花 2013-06-28
  • 打赏
  • 举报
回复
view.getLayoutParams().height view.getLayoutParams().width
Utopia 2013-06-28
  • 打赏
  • 举报
回复
图片的android:layout_width="fill_parent" android:layout_height="fill_parent" 然后把你要显示的图片setBackGroundresouce(R.d...);

80,349

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧