I programmatically add several views to the FrameLayout ( ImageView )
public class PixelGridView extends FrameLayout { ... public void addViewWithoutCoords(ImageView 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); } ... } and after adding they are not displayed, although they are there and getChildCount() returns their count. getVisibility() on them returns 0 ( VISIBLE )
After that, in this FrameLayout you can drag'n'dropat views and after the first drop all are displayed at once (and those that were not displayed)
I don’t understand what could be wrong, I’ve already google it, but I didn’t find anything like it.
EDIT
call the method to add (now the TableView is RelativeLayout )
TableView tableView = new TableView(getActivity()); ((ImageView)tableView.findViewById(R.id.ivTable)).setImageDrawable(ContextCompat.getDrawable(getActivity(), getTableResId(hallTable.type))); tableView.setOnTouchListener(new PlaceDragListener.TableTouchListener()); mPixelView.addViewWithoutCoords(tableView, hallTable.column, hallTable.row); and markup for the TableView
<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" android:src="@drawable/table_4"/> <EditText android:id="@+id/ivTableName" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@android:color/white" android:layout_centerInParent="true" android:background="@color/style_table_grey" android:text="12"/> </RelativeLayout> Now the views show almost as soon as I start dragging new views (not those that I added programmatically initially) to this container ( FrameLayout ). I do not understand what method it can cause that it displays them
invalidate()onFrameLayoutcall after adding a view - YuriiSPb ♦