Ich entwickle eine App, die die Wettervorhersage von 4 verschiedenen Regionen in 5 Tagen in der Zukunft zeigt. Jede Region zeigt 5 Tage an und jeder Tag hat seine eigenen Daten: ein TextView mit dem Namen des Tages, ein TextView mit der Hauptwetterbedingung für diesen Tag, ein ImageView mit dem Wettersymbol und zwei TextView mit dem Min Temp und Max Temp für diesen Tag. Wie folgt aus:Mehrmals dieselbe Ansicht hinzufügen - Layout erneut verwenden
ich realisiert dies in einer SUPER AWFUL layout.xml Datei, jede Textview-Behandlung und Image für alle 20 Tage der 4 Regionen getrennt:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/tv_weather_forecats_title"
style="@style/tv_weather_11"
android:text="@string/extended_forecast" />
<TextView
android:id="@+id/tv_fore_title_city"
style="@style/tv_weather_6"
android:text="@string/title_city" />
<LinearLayout style="@style/ll_weather_1">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:id="@+id/tv_fore_day1_city"
style="@style/tv_weather_7"
android:text="Mon"/>
<TextView
android:id="@+id/tv_fore_cond1_city"
style="@style/tv_weather_8"
android:text="Light Rain"/>
<ImageView
android:id="@+id/iv_fore_ic_day1_city"
style="@style/iv_weather_1"
android:src="@drawable/ic_main_broken_clouds" />
<TextView
android:id="@+id/tv_fore_min_day1_city"
style="@style/tv_weather_9"
android:text="5"/>
<TextView
android:id="@+id/tv_fore_max_day1_city"
style="@style/tv_weather_10"
android:text="15"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:id="@+id/tv_fore_day2_city"
style="@style/tv_weather_7"
android:text="Tue"/>
<TextView
android:id="@+id/tv_fore_cond2_city"
style="@style/tv_weather_8"
android:text="Light Rain"/>
<ImageView
android:id="@+id/iv_fore_ic_day2_city"
style="@style/iv_weather_1"
android:src="@drawable/ic_main_broken_clouds"/>
<TextView
android:id="@+id/tv_fore_min_day2_city"
style="@style/tv_weather_9"
android:text="5"/>
<TextView
android:id="@+id/tv_fore_max_day2_city"
style="@style/tv_weather_10"
android:text="15"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:id="@+id/tv_fore_day3_city"
style="@style/tv_weather_7"
android:text="Wed"/>
<TextView
android:id="@+id/tv_fore_cond3_city"
style="@style/tv_weather_8"
android:text="Light Rain"/>
<ImageView
android:id="@+id/iv_fore_ic_day3_city"
style="@style/iv_weather_1"
android:src="@drawable/ic_main_broken_clouds"/>
<TextView
android:id="@+id/tv_fore_min_day3_city"
style="@style/tv_weather_9"
android:text="5"/>
<TextView
android:id="@+id/tv_fore_max_day3_city"
style="@style/tv_weather_10"
android:text="15"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:id="@+id/tv_fore_day4_city"
style="@style/tv_weather_7"
android:text="Thu"/>
<TextView
android:id="@+id/tv_fore_cond4_city"
style="@style/tv_weather_8"
android:text="Light Rain"/>
<ImageView
android:id="@+id/iv_fore_ic_day4_city"
style="@style/iv_weather_1"
android:src="@drawable/ic_main_broken_clouds"/>
<TextView
android:id="@+id/tv_fore_min_day4_city"
style="@style/tv_weather_9"
android:text="5"/>
<TextView
android:id="@+id/tv_fore_max_day4_city"
style="@style/tv_weather_10"
android:text="15"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:id="@+id/tv_fore_day5_city"
style="@style/tv_weather_7"
android:text="Fri"/>
<TextView
android:id="@+id/tv_fore_cond5_city"
style="@style/tv_weather_8"
android:text="Light Rain"/>
<ImageView
android:id="@+id/iv_fore_ic_day5_city"
style="@style/iv_weather_1"
android:src="@drawable/ic_main_broken_clouds"/>
<TextView
android:id="@+id/tv_fore_min_day5_city"
style="@style/tv_weather_9"
android:text="5"/>
<TextView
android:id="@+id/tv_fore_max_day5_city"
style="@style/tv_weather_10"
android:text="15"/>
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:background="@color/colorDarkTextDivider" />
<TextView
android:id="@+id/tv_fore_title_east"
style="@style/tv_weather_6"
android:text="@string/title_east" />
<LinearLayout style="@style/ll_weather_1">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:id="@+id/tv_fore_day1_east"
style="@style/tv_weather_7"
android:text="Mon"/>
<TextView
android:id="@+id/tv_fore_cond1_east"
style="@style/tv_weather_8"
android:text="Light Rain"/>
<ImageView
android:id="@+id/iv_fore_ic_day1_east"
style="@style/iv_weather_1"
android:src="@drawable/ic_main_broken_clouds"/>
<TextView
android:id="@+id/tv_fore_min_day1_east"
style="@style/tv_weather_9"
android:text="5"/>
<TextView
android:id="@+id/tv_fore_max_day1_east"
style="@style/tv_weather_10"
android:text="15"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:id="@+id/tv_fore_day2_east"
style="@style/tv_weather_7"
android:text="Tue"/>
<TextView
android:id="@+id/tv_fore_cond2_east"
style="@style/tv_weather_8"
android:text="Light Rain"/>
<ImageView
android:id="@+id/iv_fore_ic_day2_east"
style="@style/iv_weather_1"
android:src="@drawable/ic_main_broken_clouds"/>
<TextView
android:id="@+id/tv_fore_min_day2_east"
style="@style/tv_weather_9"
android:text="5"/>
<TextView
android:id="@+id/tv_fore_max_day2_east"
style="@style/tv_weather_10"
android:text="15"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:id="@+id/tv_fore_day3_east"
style="@style/tv_weather_7"
android:text="Wed"/>
<TextView
android:id="@+id/tv_fore_cond3_east"
style="@style/tv_weather_8"
android:text="Light Rain"/>
<ImageView
android:id="@+id/iv_fore_ic_day3_east"
style="@style/iv_weather_1"
android:src="@drawable/ic_main_broken_clouds"/>
<TextView
android:id="@+id/tv_fore_min_day3_east"
style="@style/tv_weather_9"
android:text="5"/>
<TextView
android:id="@+id/tv_fore_max_day3_east"
style="@style/tv_weather_10"
android:text="15"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:id="@+id/tv_fore_day4_east"
style="@style/tv_weather_7"
android:text="Thu"/>
<TextView
android:id="@+id/tv_fore_cond4_east"
style="@style/tv_weather_8"
android:text="Light Rain"/>
<ImageView
android:id="@+id/iv_fore_ic_day4_east"
style="@style/iv_weather_1"
android:src="@drawable/ic_main_broken_clouds" />
<TextView
android:id="@+id/tv_fore_min_day4_east"
style="@style/tv_weather_9"
android:text="5"/>
<TextView
android:id="@+id/tv_fore_max_day4_east"
style="@style/tv_weather_10"
android:text="15"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:id="@+id/tv_fore_day5_east"
style="@style/tv_weather_7"
android:text="Fri"/>
<TextView
android:id="@+id/tv_fore_cond5_east"
style="@style/tv_weather_8"
android:text="Light Rain"/>
<ImageView
android:id="@+id/iv_fore_ic_day5_east"
style="@style/iv_weather_1"
android:src="@drawable/ic_main_broken_clouds"/>
<TextView
android:id="@+id/tv_fore_min_day5_east"
style="@style/tv_weather_9"
android:text="5"/>
<TextView
android:id="@+id/tv_fore_max_day5_east"
style="@style/tv_weather_10"
android:text="15"/>
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:background="@color/colorDarkTextDivider" />
<TextView
android:id="@+id/tv_fore_title_south"
style="@style/tv_weather_6"
android:text="@string/title_south" />
<LinearLayout style="@style/ll_weather_1">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:id="@+id/tv_fore_day1_south"
style="@style/tv_weather_7"
android:text="Mon"/>
<TextView
android:id="@+id/tv_fore_cond1_south"
style="@style/tv_weather_8"
android:text="Light Rain"/>
<ImageView
android:id="@+id/iv_fore_ic_day1_south"
style="@style/iv_weather_1"
android:src="@drawable/ic_main_broken_clouds"/>
<TextView
android:id="@+id/tv_fore_min_day1_south"
style="@style/tv_weather_9"
android:text="5"/>
<TextView
android:id="@+id/tv_fore_max_day1_south"
style="@style/tv_weather_10"
android:text="15"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:id="@+id/tv_fore_day2_south"
style="@style/tv_weather_7"
android:text="Tue"/>
<TextView
android:id="@+id/tv_fore_cond2_south"
style="@style/tv_weather_8"
android:text="Light Rain"/>
<ImageView
android:id="@+id/iv_fore_ic_day2_south"
style="@style/iv_weather_1"
android:src="@drawable/ic_main_broken_clouds"/>
<TextView
android:id="@+id/tv_fore_min_day2_south"
style="@style/tv_weather_9"
android:text="5"/>
<TextView
android:id="@+id/tv_fore_max_day2_south"
style="@style/tv_weather_10"
android:text="15"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:id="@+id/tv_fore_day3_south"
style="@style/tv_weather_7"
android:text="Wed"/>
<TextView
android:id="@+id/tv_fore_cond3_south"
style="@style/tv_weather_8"
android:text="Light Rain"/>
<ImageView
android:id="@+id/iv_fore_ic_day3_south"
style="@style/iv_weather_1"
android:src="@drawable/ic_main_broken_clouds" />
<TextView
android:id="@+id/tv_fore_min_day3_south"
style="@style/tv_weather_9"
android:text="5"/>
<TextView
android:id="@+id/tv_fore_max_day3_south"
style="@style/tv_weather_10"
android:text="15"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:id="@+id/tv_fore_day4_south"
style="@style/tv_weather_7"
android:text="Thu"/>
<TextView
android:id="@+id/tv_fore_cond4_south"
style="@style/tv_weather_8"
android:text="Light Rain"/>
<ImageView
android:id="@+id/iv_fore_ic_day4_south"
style="@style/iv_weather_1"
android:src="@drawable/ic_main_broken_clouds" />
<TextView
android:id="@+id/tv_fore_min_day4_south"
style="@style/tv_weather_9"
android:text="5"/>
<TextView
android:id="@+id/tv_fore_max_day4_south"
style="@style/tv_weather_10"
android:text="15"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:id="@+id/tv_fore_day5_south"
style="@style/tv_weather_7"
android:text="Fri"/>
<TextView
android:id="@+id/tv_fore_cond5_south"
style="@style/tv_weather_8"
android:text="Light Rain"/>
<ImageView
android:id="@+id/iv_fore_ic_day5_south"
style="@style/iv_weather_1"
android:src="@drawable/ic_main_broken_clouds" />
<TextView
android:id="@+id/tv_fore_min_day5_south"
style="@style/tv_weather_9"
android:text="5"/>
<TextView
android:id="@+id/tv_fore_max_day5_south"
style="@style/tv_weather_10"
android:text="15"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Auf der Java Datei Ich habe 100 Deklarationen von Ansichten und verwende 100 Zeilen, um die Instanz der Ansichten zu erhalten, und weitere 100 Setzmethoden, um Texte und Bilder zu setzen ... Ich weiß, super/unglaublich schrecklich.
Dies muss sicher schlechtes Design sein. Es muss eine Möglichkeit geben, eine einzelne Ansicht (Tag-Name, Bedingung, Bild, minimale Temperatur und maximale Temperatur) in ein Layout einzufügen und wiederzuverwenden. Irgendeine Idee?
Verwenden Sie '' Tag –
pskink