langerhans
langerhans

Reputation: 779

Inflated layout's children not showing

I am using a DraggableGridView from here.

What I did before was add a simple programmatically built ImageViews to the grid. That works perfectly fine.

I am now trying to add a Layout instead. I tried RelativeLayout, Framelayout, FrameLayout inside of a RelativeLayout.

Here is my code as of now:

/**
 * 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)));
    }
}

Following the 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>

The RelativeLayout gets inflated into the grid nicely. I can observe this via DDMS and the "Dump view hierachy" function. The tree shows all RelativeLayouts inside the grid, but each of it doesn't have any children.

BUT... That is not true. If I step through the code and observe the inflated layouts I can see the children. So they are set up, get added just like told in the XML, but don't get drawn.

The OnItemClick listener on the children of the grid also works...

Any hint about what I'm missing here? I already tried several ways, even creating the complete layout programmatically and then adding it to the grid as children. Still no luck. None of the children get added.

Is that maybe an issue with the used DraggableGridView?

Upvotes: 1

Views: 1056

Answers (1)

langerhans
langerhans

Reputation: 779

After searching for another few hours I found a fix in this SO thread

Basically I now extend DraggableGridView from FrameLayout rather than ViewGroup. This hasn't had any noticeable side effects to me.

Upvotes: 2

Related Questions