佈局僅在屏幕關閉或離開應用程序並返回後顯示兒童 (Layout only shows children after screen turn off or leaving the app and coming back)


問題描述

佈局僅在屏幕關閉或離開應用程序並返回後顯示兒童 (Layout only shows children after screen turn off or leaving the app and coming back)

I am having lots of troubles with this. It is working properly on my Nexus 7 tablet, but not on my Samsung S3.

I am adding views to a LinearLayout called ItemsBar, but nothing shows up inside it until I press the screen off button and then screen on, or if I leave the app by switching to another app and back to it. Showing the keyboard also shows the views.

//Load Images into ItemBar
    for (int currentItemImage : ItemIDs){
        ImageView i = new ImageView(this);
        i.setImageResource(currentItemImage);
        i.setTag(currentItemImage);
        i.setClickable(true);i.setPadding(4, 0, 4, 0);
        i.setOnClickListener(ItemOnClick);
        i.setLayoutParams(ItemLP);
        ItemsBar.addView(i);
    }

This is not done at OnCreate. It is done on button click. The OnStart and OnResume are unused.

By inspecting, the layout does have 20 children.

Note: to prove that there is nothing wrong with this code, resources, and Params, they actually do show up after screen turn off or switching app. And this works perfectly on the Nexus 7.

I tried using invalidate() to children and to the layout, to no avail.

What can I do?


參考解法

方法 1:

Try to call ItemsBar.requestLayout() after all items were added.

方法 2:

The error was in OnLayoutChangeListener(). It seems that Nexus 7 with Android 4.3 dealt differently (maybe requested it differently) than my Samsung S3 with Android 4.1.2. I had to remove it completely.

(by zedsergej shafarenkazed)

參考文件

  1. Layout only shows children after screen turn off or leaving the app and coming back (CC BY‑SA 3.0/4.0)

#draw #Android






相關問題

使用Java繪製維恩圖 (Draw Venn diagram using Java)

android中的ontouch:獲取X和Y坐標並在該點上繪製圓 (ontouch in android: getting X and Y coordinates and drawing circle on that point)

如何在android上將谷歌地圖圖層作為片段佈局移動 (how to move google map layers as fragment layout on android)

onTouch() 無法繪製畫布 (onTouch() can't draw canvas)

佈局僅在屏幕關閉或離開應用程序並返回後顯示兒童 (Layout only shows children after screen turn off or leaving the app and coming back)

將形狀對象的 ArrayList 繪製到框架 (Paint ArrayList of Shape Objects to Frame)

多線程圖形 (multithreading Graphics)

一次性繪製所有 DrawableGameComponents (Drawing all DrawableGameComponents in a single batch)

html5畫布繪製帶有額外數據的圓形變量 (html5 canvas draw circle variables with extra data)

iphone初學者問題:畫一個矩形。我究竟做錯了什麼? (Beginner iphone question: drawing a rectangle. What am I doing wrong?)

連接 4 Android Studio 繪製空格 (Connect 4 Android Studio Draw empty spaces)

矩形不動 (Rectangle is not moving)







留言討論