2013-08-01 20 views
1

我正在使用DraggableGridViewfrom here充气版式的孩子没有显示

我之前做过的是在网格中添加一个简单的程序编写的ImageViews。这很好。

我现在试图添加一个Layout来代替。我试过RelativeLayout,Framelayout,FrameLayout里面的RelativeLayout

这里是我的代码截至目前:

/** 
* Rebuild the grid view, e.g. after the adapter has been filled or a backup is restored 
*/ 
private void renewGrid() 
{ 
    dgv.removeAllViews(); 
    for(int i = 0; i < adapter.getCount(); i++) 
    { 
     LayoutInflater inflater = (LayoutInflater)ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     dgv = (DraggableGridView) inflater.inflate(R.layout.grid_item_layout, dgv); 
     FrameLayout fl = (FrameLayout) dgv.findViewById(R.id.grid_images); 
     ImageView icon = (ImageView) fl.findViewById(R.id.qstile); 
     icon.setImageDrawable(res.getDrawable(res.getIdentifier("qstile_" + adapter.getItem(i), "drawable", packagename))); 
    } 
} 

继grid_item_layout:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:gravity="center_vertical" 
    android:orientation="horizontal" > 

    <FrameLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/grid_images"> 
     <ImageView 
      android:layout_width="32dp" 
      android:layout_height="32dp" 
      android:src="@drawable/icon_delete"/> 

     <ImageView 
      android:id="@+id/qstile" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"/> 
    </FrameLayout> 

    <TextView 
     android:id="@+id/invisible_text" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:text="" 
     android:visibility="gone" /> 

</RelativeLayout> 

RelativeLayout被很好地膨胀到电网。我可以通过DDMS和“转储视图层次”功能观察到这一点。树显示网格内的所有RelativeLayouts,但每个都没有任何子节点。

但是......那是不正确的。如果我浏览代码并观察膨胀的布局,我可以看到孩子们。因此,它们的设置,就像在XML中告诉的那样添加,但不会被绘制。

的网格上也适用的儿童OnItemClick listener ...

关于什么我失踪这里任何提示?我已经尝试了几种方法,甚至以编程方式创建完整的布局,然后将其作为子项添加到网格中。仍然没有运气。没有一个孩子被添加。

这可能是使用DraggableGridView的问题吗?

回答

2

寻找另一个几个小时后,我发现在this SO thread

修复基本上我现在从FrameLayout而不是ViewGroup延伸DraggableGridView。这对我没有任何明显的副作用。

+1

你救了我兄弟:) –