我看了下CSDN博客中的文章,然后代码如下:
在OnGreat中对某一个TextView操作
final TextView widget79 = (TextView) findViewById(R.id.widget79);
AbsoluteLayout.LayoutParams linearParams = (AbsoluteLayout.LayoutParams)widget79.getLayoutParam();
linearParams.height = 70;
widget79.setLayoutParams(linearParams); 这样程序运行会报错关闭,屏蔽以上代码就正常
另外,怎么设置绝对位置?
在OnGreat中对某一个TextView操作
final TextView widget79 = (TextView) findViewById(R.id.widget79);
AbsoluteLayout.LayoutParams linearParams = (AbsoluteLayout.LayoutParams)widget79.getLayoutParam();
linearParams.height = 70;
widget79.setLayoutParams(linearParams); 这样程序运行会报错关闭,屏蔽以上代码就正常
另外,怎么设置绝对位置?
getWindowManager().getDefaultDisplay().getMetrics(dm);
int screenWidth = dm.widthPixels;
int screenHeight = dm.heightPixels;
Button mButtonLeft = (Button)findViewById(R.id.button01);
Button mButtonRight = (Button)findViewById(R.id.button02);
mButtonLeft.setWidth(screenWidth / 3);
mButtonRight.setWidth((screenWidth * 2) / 3);
final TextView widget79 = (TextView) findViewById(R.id.widget79) ,这种写在xml里面的 View 是不能控制其在screen上的位置吧。
只能new 一个新的view ,然后指定它的位置,再用layout的 addView 方法把它添加到layout中。
然后再在OnGreat中设置其属性,大小位置等?
AbsoluteLayout.LayoutParams params = new AbsoluteLayout.LayoutParams(w, h, x, y);
mLayout.updateViewLayout(mLayoutScrollView, params);