There is a layout

 <LinearLayout android:id="@+id/layout" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:layout_marginTop="10dp" android:background="@drawable/background"> </LinearLayout> 

which is inside RelativeLayout , this RelativeLayout is inside ScrollView . I programmatically create components in this leyaut. Components are different ( TextView , EditText , Spinner , etc.). This layer has a background (a simple background with rounded edges and a 1dp stroke). On the emulator, everything works fine, there are no lags. But it is necessary to throw apk on the device, as there are 2 problems:

  1. If there are a lot of components (more than 20), then for some reason the background disappears. Ie it generally seemed not to be.
  2. If there are not many components (less than 20) - the background is there, but it lags terribly when scrolling. Strongly freezes. It is worth adding a few components - as the background disappears and nothing lags.

Why it happens? thank

    1 answer 1

    Read about ListView , I will briefly say that it keeps in memory only what gets on the screen, and when you scroll loads. You have 20 pieces on the screen at once, it’s moveton, but what if there are 100 pieces? What you are trying to do is fundamentally wrong.

    Still wondering why are you doing all this programmatically?)

    Follow Guideline , to the left is a list of everything.

    • there will not be many components. maximum 10-15. I'm wondering why the emulator does not lag, but on the device lags? Yes, and lags appear exactly when the background is used in the leuta. there is a simple background that has a color, a 1dp stroke and rounded corners. - dexter