安卓:寻找尺寸(分辨率明智)一个的图库视图 [英] Android: Finding size (resolution-wise) of a GalleryView

查看:115
本文介绍了安卓:寻找尺寸(分辨率明智)一个的图库视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个布局其中图库 高度 WRAP_CONTENT(宽度为FILL_PARENT) 80dp 的底部边缘。这将使 80dp 在屏幕下方别的东西。

I have a layout where the Gallery height is WRAP_CONTENT (width is FILL_PARENT) with bottom margin of 80dp. This would leave 80dp at bottom of screen for something else.

问题是我怎么能找出到底是多少像素我必须在高度这个图库 ?结果我需要这个以设定的位图的大小画廊的 getView (我想每个图像占用一个全库屏幕),各种设备应该给我不同的高度像素...

The problem is how can I find out exactly how many pixels do I have in the height of this Gallery?
I need this in order to set the size of the bitmap in Gallery's getView (as I want each image to take up a full Gallery screen) Various devices should give me different height pixels...

显然,当我查询 Gallery.getHeight ,则返回零。

Apparently when I query Gallery.getHeight, it returns zero.

另外,如果图像本身比画廊视口变小,我想它的规模了。然而 setScaleType(FIT_CENTER)似乎只缩小(如果图像大于视窗较大),但不扩大规模?我缺少的东西吗?

Also, if the image itself is smaller than the Gallery view port, I want to scale it up. However setScaleType(FIT_CENTER) seems to only scale down (if image is larger than viewport) yet does not scale up? Am I missing something?

在此先感谢您的帮助。

推荐答案

图库只是另一个查看,所以为查看定义的任何方法将工作。使用 myGalery.getHeight();

Gallery is just another View, so any method defined for View will work. Use myGalery.getHeight();

查看 API参考页:的 http://developer.android.com/reference/android/view/View.html

From the View API reference page: http://developer.android.com/reference/android/view/View.html

大小,空白和边距

的图的大小是具有宽度和高度pssed前$ P $。视图实际拥有2双宽度和高度值的。

The size of a view is expressed with a width and a height. A view actually possess two pairs of width and height values.

第一对被称为测量宽度和测量高度。这些尺寸定义视图想有多大成为其父项内(见布局更多的细节。)测得的尺寸可以通过调用getMeasuredWidth()和getMeasuredHeight()获得。

The first pair is known as measured width and measured height. These dimensions define how big a view wants to be within its parent (see Layout for more details.) The measured dimensions can be obtained by calling getMeasuredWidth() and getMeasuredHeight().

第二对被简单地称为宽度和高度,或有时拉伸宽度和绘图高度。这些尺寸限定在屏幕视图的实际尺寸,在拉丝时间及布局之后。这些值可以,但不必,是从所测量的宽度和高度不同。的宽度和高度可以通过调用的getWidth()和getHeight()来获得。

The second pair is simply known as width and height, or sometimes drawing width and drawing height. These dimensions define the actual size of the view on screen, at drawing time and after layout. These values may, but do not have to, be different from the measured width and height. The width and height can be obtained by calling getWidth() and getHeight().

要衡量它的尺寸,以便考虑到它的填充。该填充是在左,上,右视图的底部部分像素pssed前$ P $。填充可以用于通过象素的特定量,以抵消视图的内容。例如,为2的左填充将由2个像素推视图的内容到左边缘的右边。填充可以使用setPadding(INT,INT,INT,INT)方法调用getPaddingLeft(),getPaddingTop(),getPaddingRight()和getPaddingBottom()来设置和查询。

To measure its dimensions, a view takes into account its padding. The padding is expressed in pixels for the left, top, right and bottom parts of the view. Padding can be used to offset the content of the view by a specific amount of pixels. For instance, a left padding of 2 will push the view's content by 2 pixels to the right of the left edge. Padding can be set using the setPadding(int, int, int, int) method and queried by calling getPaddingLeft(), getPaddingTop(), getPaddingRight() and getPaddingBottom().

要小心,你什么时候测量的。如果你使用它的构造方法,它会返回零,因为它尚未得出。除非你是绝对肯定的 GridView控件将是你衡量它的时候可见,可以通过增加测量一个 View.OnLayoutChangeListener 和实施


Update

Be careful when are you measuring it. If you use it on the constructor, the it will return zero since it was not drawn yet. Unless you are absolutely sure that the GridView will be visible by the time you measure it, you can measure by adding an View.OnLayoutChangeListener and implementing

public abstract void onLayoutChange (View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) 

http://developer.android.com/reference/android/view/View.OnLayoutChangeListener.html

或覆盖保护无效onSizeChanged(INT W,INT小时,INT oldw,诠释oldh)

这篇关于安卓:寻找尺寸(分辨率明智)一个的图库视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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