Lay'O
Lay'O

Reputation: 57

Views are invisible after they was added into ViewGroup

I'm adding views programatically into FrameLayout:

public class PixelGridView extends FrameLayout {
...
     public void addViewWithoutCoords(TableView view, int column, int row) {
            float x = column * mCellSideSize;
            float y = row * mCellSideSize;

            FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT);
                view.setLayoutParams(lp);

            view.setLeft(0);
            view.setTop(0);

            view.setX(x);
            view.setY(y);
            view.setVisibility(VISIBLE);
            addView(view);
        }
...
}

However, all they are somehow invisible. getChildCount() returns count with all of them. getVisibility() for each added view also returns VISIBLE.

I can drag'n'drop such views from another ViewGroup into my Framelayout and when I do this, all earlier added views become visible.

view layout file:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent">
    <ImageView
        android:id="@+id/ivTable"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"/>
    <EditText
        android:id="@+id/ivTableName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:background="@color/style_table_grey"
        android:textColor="@android:color/white"/>
</RelativeLayout>

Even If I add new view without drag everything become visible.

Upvotes: 0

Views: 161

Answers (2)

DysaniazzZ
DysaniazzZ

Reputation: 845

The item view of the FrameLayout and RelativeLayout can be overlapping. If two item views are in the same positions of FrameLayout, the first loaded item will be covered by the later item.

Upvotes: 1

Chen Li
Chen Li

Reputation: 31

Try turn on the show layout bounds in developer option of your android devices,and find the position of your item.

Upvotes: 0

Related Questions