更改视图位置 [英] Change View position

查看:118
本文介绍了更改视图位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的看法是没有编程产生,但它发现findbyid功能。越来越视图之后,我喜欢正确定位。

My View is not generated programmatically, but it is found with findbyid function. After getting view I like to position it properly.

要做到这一点,我使用的布局功能改变视图位置的onCreate与给定的参数。问题是,无法正常工作,并查看停留在左上角。

To do that I am using layout function to change position of view in onCreate with given parameters. Problem is that is not working properly and view stays in top left corner.

而onTouch使用它的活性被加载后功能工作正常。什么我做错了,有另一种为基于布局使用。

Function works fine while using it onTouch after activity is loaded. What I am doing wrong, is there another to set view based on these four parameters that layout uses.

编辑:

PARAMS从数据库加载。
这是我在使用的onCreate:

Params are loaded from DB. this is what I use in onCreate:

setContentView(R.layout.baseview);

View view=(ImageView) findViewById(R.id.blah);      

int top=cursor.getInt(cursor.getColumnIndex(CallerViewDB.TOP));
int bottom=cursor.getInt(cursor.getColumnIndex(CallerViewDB.BOTTOM));
int left=cursor.getInt(cursor.getColumnIndex(CallerViewDB.LEFT));
int right=cursor.getInt(cursor.getColumnIndex(CallerViewDB.RIGHT));
view.layout(left, top, right, bottom);

加载的值是正确的,检查了它W¯¯sqllite浏览器。看来,在调用的onCreate布局函数没有任何东西。有没有什么别的选择吗?

Loaded values are right, checked it w sqllite browser. It seems that calling layout function in onCreate does not anything. Is there any alternative?

推荐答案

好一些reasearch后,这是它是如何做的:

Ok after some reasearch this is how it is done:

RelativeLayout.LayoutParams parms=new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);
parms.leftMargin=left;
parms.rightMargin=right;
parms.topMargin=top;
parms.bottomMargin=bottom;
view.setLayoutParams(parms);

这篇关于更改视图位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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