0

I want to have 5 imageviews, one next to each other (horizontally) and each imageview should have the width of 1/5 the screen. Instead of measuring and setting widths inside the activity, I achieved the result using linear layouts this way:

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:orientation="vertical">

        <com.davidbalas.brawlstarsinfo.CustomTextView
            android:id="@+id/nameTextView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:textColor="@android:color/white"
            android:textSize="28sp"
            android:textStyle="bold"
            app:fontName="supercell.ttf" />


        <com.davidbalas.brawlstarsinfo.CustomTextView
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColor="@android:color/white"
            android:textSize="12sp"
            android:textStyle="bold"
            app:fontName="supercell.ttf" />

        <com.davidbalas.brawlstarsinfo.CustomTextView
            android:id="@+id/top5"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:text="@string/top_5_brawlers_for"
            android:textColor="@android:color/white"
            android:textSize="22sp"
            android:textStyle="bold"
            app:fontName="supercell.ttf" />

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:orientation="horizontal">

            <ImageView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:contentDescription="@string/top_5_brawlers_for"
                android:src="@drawable/barley" />

            <ImageView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:contentDescription="@string/top_5_brawlers_for"
                android:src="@drawable/barley" />

            <ImageView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:contentDescription="@string/top_5_brawlers_for"
                android:src="@drawable/barley" />

            <ImageView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:contentDescription="@string/top_5_brawlers_for"
                android:src="@drawable/barley" />

            <ImageView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:contentDescription="@string/top_5_brawlers_for"
                android:src="@drawable/barley" />

        </LinearLayout>

    </LinearLayout>

However, I get an error nested weights are bad for performance. What is a good, other way, to achieve what I am looking for?

DAVIDBALAS1
  • 484
  • 10
  • 31

1 Answers1

0

I would solve this problem this way;

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
 <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

     <ImageView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
             />
     <ImageView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
             />
     <ImageView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
             />
     <ImageView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
             />
     <ImageView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
             />


 </LinearLayout>


</LinearLayout>
mancini13
  • 35
  • 1
  • 10