基本上我试图为平板电脑制作应用程序。 用户将在桌面布局中添加和删除一堆小部件。它需要是动态的,以便根据表格布局的宽度和高度来调整窗口大小的大小。获取Android屏幕的尺寸
要做到这一点,我试图在tablelayout中制作一个3x3网格。我敢肯定,你猜对了,每个广场的桌面布局宽度和高度都有33%。
这是我得到:
DisplayMetrics metrics;
int totalScreenSizeH;
int totalScreenSizeW;
TableLayout contentTable;
LinearLayout contentLayout;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//Get the UI detail
metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
totalScreenSizeH = metrics.heightPixels;
totalScreenSizeW = metrics.widthPixels;
contentTable=(TableLayout)findViewById(R.id.tableLayout1);
contentLayout=(LinearLayout)findViewById(R.id.contentLayout);
int tableWidth =contentTable.getWidth();
int tableHeight=contentTable.getHeight();
int layoutWidth=contentLayout.getWidth();
int layoutHeight=contentLayout.getHeight();
Log.v("Table Width",""+tableWidth);
Log.v("Table Height",""+tableHeight);
Log.v("Layout Width",""+layoutWidth);
Log.v("Layout Height",""+layoutHeight);
所以才来解释这一点更好。 linearLayout包含具有3个表格行的表格布局。我认为我能够获得这些宽度和高度,但由于某种原因,两者的尺寸都是0。一个我有宽度和高度变暗,我将保存该变量,并基于这些变量/ 3创建小部件。
所以2个问题:
1:是这样来处理动态调整大小部件的正确途径。或者这是处理这样的问题的错误方法?
2:为什么这些2-4变量都回来为0的任何想法?
我不知道确切的答案,但我可以指出你的资源,这将帮助你巨大支持表和电话(和各种维度),以及支持仪表板布局(这听起来像你的东西用你的3x3网格来描述)。谷歌2011年IO应用程序有一些伟大的指导方针,我建议采取看看来源,看看他们在这里做了什么:http://code.google.com/p/iosched/ – Jack