在Android的Posision视图(ImageView的)编程 [英] Posision a view (imageView) programatically in Android

查看:198
本文介绍了在Android的Posision视图(ImageView的)编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题似乎很简单,但我无法找到答案。
我需要放置的ImageView在屏幕中的特殊地位。假如,我需要它是从前三名十分之一,从屏幕左侧五分之一。

This problem might seem very basic but I couldn't find an answer to it. I need to place an imageView in a special position in the screen. Suppose, I need it to be three tenth from the top, and one fifth from the left of the screen.

,想到的第一件事是使用AbsoluteLayout并将使用绝对坐标ImageView的。然而,这种方法会导致不同屏幕尺寸的工作问题。
问题是,我不能在XML文件中的屏幕尺寸(宽度和高度),而在另一方面,我无法找到一个setX的()/塞蒂()或类似方法的ImageView以编程方式做到这一点。

The first thing that comes to mind is to use an AbsoluteLayout and place the imageView using absolute coordinates. However this method causes problems in working with different screen sizes. The problem is that I can not get the screen dimensions (width and height) in the xml file, and on the other hand, I couldn't find a setX() / setY() or similar method for ImageView to do it programatically.

要解决这个问题的一个想法是使用的LinearLayout代替AbsoluteLayout和插入虚设次(像textVies)填补后面或我的上述期望的ImageView的空间。但此变得复杂,如果我有多个imageViews在屏幕放置,并且如果期望的位置并不对准。
另一种解决方案是使用填充或余量,但它没有与AbsoluteView工作

An idea to solve this problem was using LinearLayout instead of AbsoluteLayout and to insert dummy views (like textVies) to fill the space behind or above my desired imageView. But this gets complicated if I have multiple imageViews to place in the screen and if the desired positions are not aligned. Another solution was using padding or margin, but it didn't work with the AbsoluteView.

推荐答案

这是这样的:

    AbsoluteLayout.LayoutParams lp=new AbsoluteLayout.LayoutParams(width,height,x,y);
    myImageView.setLayoutParams(lp);

这篇关于在Android的Posision视图(ImageView的)编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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