如何找到时,它在Android应用中心对齐图像视图的高度和宽度? [英] how to find the height and width of the image view when it is aligned center in android app?
本文介绍了如何找到时,它在Android应用中心对齐图像视图的高度和宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是我的code的片段
<?XML版本=1.0编码=UTF-8&GT?;
<的FrameLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@ + ID / framelayouts
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:layout_gravity =中心
> < ImageView的
机器人:ID =@ + ID / imageviews
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:layout_gravity =中心
机器人:SRC =@绘制/ ic_launcher/>< /&的FrameLayout GT;
现在能够在中心获取图像。
问题:
下面的问题就是我得到一些未使用的空间,顶部和底部,我怎么能找到图像的未使用的空间或高度或仅imageheight的高度?
截图:
解决方案
私人无效getImageViewDimension(){
// TODO自动生成方法存根
新的处理程序()。postDelayed(新的Runnable(){
@覆盖
公共无效的run(){ INT actualImgWidth = mDeviceWidth - mImgView.getX();
INT actualImgHeight = mDeviceHeight - mImgView.getY();
Toast.makeText(getApplicationContext(),actualImgWidth,actualImgHeight:+ actualImgWidth +,+ actualImgHeight,
Toast.LENGTH_SHORT).show(); INT宽度= mImgView.getWidth();
INT高度= mImgView.getHeight(); }
},10L);
}
Here is my snippet of code
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/framelayouts"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
>
<ImageView
android:id="@+id/imageviews"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:src="@drawable/ic_launcher" />
</FrameLayout>
now am able to get the image at center .
Problem:
Here Problem is i am getting some un used space top and bottom, how can i find the height of the unused space or height of the image or only the imageheight ?
Screenshot:
解决方案
private void getImageViewDimension() {
// TODO Auto-generated method stub
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
int actualImgWidth = mDeviceWidth - mImgView.getX();
int actualImgHeight = mDeviceHeight - mImgView.getY();
Toast.makeText(getApplicationContext(), "actualImgWidth ,actualImgHeight:" +actualImgWidth +","+actualImgHeight ,
Toast.LENGTH_SHORT).show();
int Width = mImgView.getWidth();
int Height = mImgView.getHeight();
}
}, 10L);
}
这篇关于如何找到时,它在Android应用中心对齐图像视图的高度和宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文