相关疑难解决方法(0)

如何检索视图的尺寸?

我有一个观点TableLayout, TableRow and TextView.我希望它看起来像一个网格.我需要得到这个网格的高度和宽度.这些方法getHeight()getWidth()总是返回0.这发生在我和动态也格式化网格时我使用XML版本.

如何检索视图的尺寸?


这是我在Debug中用来检查结果的测试程序:

import android.app.Activity;
import android.os.Bundle;
import android.widget.TableLayout;
import android.widget.TextView;

public class appwig extends Activity {  
    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.maindemo);  //<- includes the grid called "board"
      int vh = 0;   
      int vw = 0;

      //Test-1 used the xml layout (which is displayed on the screen):
      TableLayout tl = (TableLayout) findViewById(R.id.board);  
      tl = (TableLayout) findViewById(R.id.board);
      vh = tl.getHeight();     //<- getHeight returned 0, Why?  
      vw = tl.getWidth();     //<- …
Run Code Online (Sandbox Code Playgroud)

layout lifecycle android android-widget measure

207
推荐指数
6
解决办法
13万
查看次数

屏幕大小蜂窝菜单android

嗨,我想你得到屏幕的屏幕尺寸减去底部的菜单栏.

我知道我可以根据设备的分辨率减去一个常数,但这是一个超级难看的黑客.我相信谷歌人不会傻到忘记给用户一个功能来获取底部菜单栏的高度,这样我就可以从全屏尺寸中减去它

这是一篇类似的帖子. android通知栏和标题栏的大小?

DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);

what_i_need =metrics.heightPixels-buttomMenuHeight();
Run Code Online (Sandbox Code Playgroud)

我需要buttomMenuHeight();

我在API中找不到它.在这一点上,我并不真正关心落后的可比性

谢谢

size android screen android-3.0-honeycomb

3
推荐指数
1
解决办法
3029
查看次数