如何找到时,它在Android应用中心对齐图像视图的高度和宽度?它在、视图、宽度、图像

2023-09-07 01:03:17 作者:举起手来蹲墙角去

下面是我的code的片段

 <?XML版本=1.0编码=UTF-8&GT?;<的FrameLayout的xmlns:机器人=htt​​p://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; 

现在能够在中心获取图像。

问题:

android ui检视插件,Android工具之被忽略的UI检视利器 Hierarchy Viewer

下面的问题就是我得到一些未使用的空间,顶部和底部,我怎么能找到图像的未使用的空间或高度或仅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);
}