小编may*_*hem的帖子

在Android中获取布局的宽度/高度

我想知道如何测量视图的尺寸.就我而言,它是绝对布局.我已经阅读了有关这些问题的答案,但我仍然没有得到它.

这是我的代码:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main);      

    AbsoluteLayout layoutbase = (AbsoluteLayout) findViewById(R.id.layoutbase);       

    drawOval(); 

}
public void drawOval(){ //, int screenWidth, int screenHeight){ 
    AbsoluteLayout layoutbase = (AbsoluteLayout) findViewById(R.id.layoutbase);     

    int screenWidth = layoutbase.getWidth();
    int screenHeight = layoutbase.getHeight();
    Log.i("MyActivity", "screenWidth: " + screenWidth + ", screenHeight: " +screenHeight);

    Coordinates c = new Coordinates(BUTTONSIZE,screenWidth,screenHeight);

    ...some code ...

    ((ViewGroup) layoutbase ).addView(mybutton, new AbsoluteLayout.LayoutParams(BUTTONSIZE, BUTTONSIZE, c.mX, c.mY));


    mybutton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            showText(mybutton);
        }
    });
}

public void showText(View button){      

    int …
Run Code Online (Sandbox Code Playgroud)

android android-layout

9
推荐指数
2
解决办法
4万
查看次数

标签 统计

android ×1

android-layout ×1