1
我真的在尝试一些非常简单的事情,不过android和java让我的生活变得不容易。这个想法是滚动到表格布局中的指定的孩子。tablelayout getchildat滚动到那个孩子
我使用的是Layoutinflater的条目添加到像表布局如下:
TableLayout tl = (TableLayout)findViewById(R.id.myTableLayout3);
LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View itemView = inflater.inflate(R.layout.element_news, null);
TextView firstname = (TextView) itemView.findViewById(R.id.tvname);
firstname.setText(FN + " " + iLN);
TextView date = (TextView) itemView.findViewById(R.id.tvdate);
date.setText(newPD);
TextView post = (TextView) itemView.findViewById(R.id.tvpost);
post.setText(c.getString(iP));
post.setFocusable(true);
tl.addView(itemView, new TableLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
我试图用getChildAt()为tablelayout和我得到这个孩子,但是当我使用孩子返回一切为“0”的孩子。
例如代码:
LinearLayout row = (LinearLayout) tl.getChildAt(1);
TextView tv = (TextView) row.getChildAt(1);
tv.requestFocus();
Log.w("news", Integer.toString(tv.getHeight()));
对于TextView的高度则返回“0”尽管它已经包含多个线和requestFocus()方法也不起作用。
那么如何滚动到表格布局中的孩子?
在此先感谢您的帮助。
非常感谢它为我工作。 – Max
只要22小时过去了,我就会给你+50的声望点。 – Max