Добавить представления по вертикали в LinearLayout - PullRequest
1 голос
/ 17 октября 2019

Я пытаюсь добавить views по вертикали в LinearLayout, как на картинке ниже:

enter image description here

код ниже дает мне что-то вродеэто:

enter image description here

 private void configure(View view) {
        LinearLayout palletContainer = view.findViewById(R.id.palette_container);
        fillPalletColors(mPalette, palletContainer);
    }
private void fillPalletColors(List<Integer> colors, LinearLayout paletteContainer) {
        if (getActivity() != null && isAdded()) {
            LayoutInflater inflater = getActivity().getLayoutInflater();
                for (int color : colors) {
                    View palletColor = inflater.inflate(R.layout.suggested_color_item_center, paletteContainer, false);
                    palletColor.setBackgroundColor(color);
                    paletteContainer.addView(palletColor);
                }
            }
    }

XML :

   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:orientation="vertical">

     <LinearLayout
        android:id="@+id/palette_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="vertical" />
  </LinearLayout>
...