I am creating an app that shows business card like images of discounts for businesses around my state.
I got a warning saying:
restaurants_mugshots_grill_and_bar_card <androidx.cardview.widget.CardView>: Layout has too many views
The layout file I have looks something like this:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
tools:ignore="SpeakableTextPresentCheck">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFC107"
android:padding="40dp"
tools:context=".RestaurantsActivity">
<!-- 306 BBQ-->
<androidx.cardview.widget.CardView
android:id="@+id/restaurants__306_BBQ_card"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:cardCornerRadius="0dp"
app:cardElevation="4dp">
<ImageView
android:id="@+id/restaurants__306_BBQ"
android:layout_width="match_parent"
android:layout_height="200dp"
android:contentDescription="@string/restaurants_306_bbq_logo"
android:src="@drawable/activity_alabama_music_hall_of_fame_card"
android:scaleType="fitXY"/>
<LinearLayout
style="?android:attr/buttonBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="bottom"
android:gravity="center_horizontal">
<Button
android:id="@+id/restaurants__306_BBQ_Facebook"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="@string/r_306bbqFB"
android:background="@android:color/transparent"
tools:ignore="VisualLintButtonSize" />
<Button
android:id="@+id/restaurants__306_BBQ_Instagram"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="@string/r_306bbqIG"
android:background="@android:color/transparent"
tools:ignore="VisualLintButtonSize" />
<Button
android:id="@+id/restaurants__306_BBQ_Website"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="@string/r_306bbqWeb"
android:background="@android:color/transparent"
tools:ignore="VisualLintButtonSize" />
<Button
android:id="@+id/restaurants__306_BBQ_Directions"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="@string/r_306bbqDir"
android:background="@android:color/transparent"
tools:ignore="VisualLintButtonSize" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<!-- Big Bad Breakfast-->
<androidx.cardview.widget.CardView
android:id="@+id/restaurants_big_bad_breakfast_card"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/restaurants__306_BBQ_card"
app:cardCornerRadius="0dp"
app:cardElevation="4dp">
<ImageView
android:id="@+id/restaurants_big_bad_breakfast"
android:layout_width="match_parent"
android:layout_height="200dp"
android:contentDescription="@string/restaurants_big_bad_breakfast_logo"
android:src="@drawable/activity_alabama_music_hall_of_fame_card"
android:scaleType="fitXY"/>
<LinearLayout
style="?android:attr/buttonBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="bottom"
android:gravity="center_horizontal">
<Button
android:id="@+id/restaurants_big_bad_breakfast_facebook"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="@string/rbbbFB"
android:background="@android:color/transparent"
tools:ignore="VisualLintButtonSize" />
<Button
android:id="@+id/restaurants_big_bad_breakfast_Instagram"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="@string/rbbbIG"
android:background="@android:color/transparent"
tools:ignore="VisualLintButtonSize" />
<Button
android:id="@+id/restaurants_big_bad_breakfast_Website"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="@string/rbbbWeb"
android:background="@android:color/transparent"
tools:ignore="VisualLintButtonSize" />
<Button
android:id="@+id/restaurants_big_bad_breakfast_Directions"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="@string/rbbbDir"
android:background="@android:color/transparent"
tools:ignore="VisualLintButtonSize" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
As of right now I have 12 of those card views in the one XML layout, and I will be adding around 9 more at the moment, and much more in the future.
Would it be more beneficial to just create a layout.xml file for each one?
and if that is the case, is there a way I can put them inside a folder? I am doing this for many different businesses not just restaurants, restaurants just have the most. I do not to see 200 different XML files in my project navigator if I do not have to, and I would like to be able to organize them by business category, i.e. activities, health and beauty, restaurants, services etc...
I have been putting them all in one file as of right now and it works, I just do not want to deal with any warnings or errors in the future.