我试图让adapterview正确绘制其子视图,但无法获取适配器返回的视图的子视图进行绘制。具体来说,我的适配器应该吐出简单的看法是这样的:使用adapterview时,无法在视图组中绘制子视图
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF">
<TextView
android:id="@+id/photo_cell_contents"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10px"
android:text="@string/photo_cell_default_text"
android:textColor="#000000"
android:textSize="80px"/>
</LinearLayout>
适配器的getView()方法被调用,并确实返回此欣赏到适配器视图的实例。我还在我的adapterview中添加了断点,并且可以看到存在适当的视图层次结构 - 具有子级textview对象的根线性布局。但是,当适配器视图布局并绘制适配器返回的子视图时,内部文本视图不会被绘制。我看到与每个单元格对应的实际彩色框,但不包括应该出现在内部的文本。有没有人知道为什么会发生这种情况?下面是,规定了儿童的意见(这时候我setAdapter得到补充()和我通过适配器视图滚动会得到更新)适配器视图的onLayout()方法的代码:
for (int idx = 0; idx < this.getChildCount(); idx++) {
if (idx != dragged)
{
Point xy = getCoorFromIndex(idx);
View child = getChildAt(idx);
child.layout(xy.x, xy.y, xy.x + childSize, xy.y + childSize); //view group will layout the children based on the sizes determined for available columns
int left = child.getLeft();
int right = child.getRight();
int top = child.getTop();
View tv = ((ViewGroup)child).getChildAt(0);
int tvleft = tv.getLeft();
int tvright = tv.getRight();
int tvtop = tv.getTop();
Log.i("dgv", "Here is info about main view ... left = " + left + "; right = " + right + "; top = " + top);
Log.i("dgv", "Here is info about text view ... left = " + tvleft + "; right = " + tvright + "; top = " + tvtop);
}
}
一个想法:你没有正确设置文本?如果它正在绘制视图,则问题可能是文本设置。如果您发布了一些代码,我可以尝试帮助您进行调试。 – AJcodez 2012-03-01 18:15:49
你有想过吗?有类似的问题... – NPike 2012-04-04 01:30:44
是的,见下文。 – Faisal 2012-05-02 15:42:51