如何在Android应用程序中对齐中心时查找图像视图的高度和宽度? [英] how to find the height and width of the image view when it is aligned center in android app?

查看:254
本文介绍了如何在Android应用程序中对齐中心时查找图像视图的高度和宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码片段

 <?xml version =1.0encoding =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>

现在可以在中央取得图片。



问题:



这里问题是我得到一些未使用的空间顶部和底部,


解决方案

  private void getImageViewDimension(){
// TODO自动生成方法存根
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宽度= mImgView.getWidth();
int Height = 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆