2013-08-01 19 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

你救了我兄弟:) –