Introduction to the

Create Sunshine, the android weather app, and add some virtual weather data to the home page to display the weather list.

Implementation steps

Step 1: Project creation

Using the Android Studio tool to create a new project, the steps are as follows:

  1. Open Android Studio and select Create New Project
  2. Select the Empty Activty project template and click Next
  3. Enter the application Name Sunshine in the Name field, leave the rest as default, and click Finish
  4. Project creation completed

Step 2: Display the text

Add a scrollable text tag to the home page layout file activity_forecast.xml to display weather information

<ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    <TextView
        android:id="@+id/tv_weather_data"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="16dp"
        android:textSize="20sp" />
</ScrollView>
Copy the code

Step 3: Display the text list

During the creation of the main interface, obtain the reference of the text label and set the content to be displayed as the prepared virtual data

mWeatherTextView = findViewById(R.id.tv_weather_data);

String[] dummyWeatherData = {
        "Today, May 17-clear-17 °C / 15°C"."Cloudy - 19°C / 15°C"."Thursday-rainy - 30°C / 11°C"."Storms - 21°C / 9°C"."Saturday - Thunderstorms - 16°C / 7°C"."Sunday-rainy -16 °C / 8°C"."Monday - Cloudy - 15°C / 10°C"."Tue, May 24 - Meatballs - 16°C / 18°C"."Wed, May 25-cloudy - 19°C / 15°C"."Thu, May 26-Stormy - 30°C / 11°C"."Fri, May 27-hurricane - 21°C / 9°C"."Sat, May 28 - Meteors - 16°C / 7°C"."Sun, May 29 - Apocalypse - 16°C / 8°C"."Mon, May 30 - Post Apocalypse - 15°C / 10°C"};for (String dummyWeatherDay : dummyWeatherData) {
    mWeatherTextView.append(dummyWeatherDay + "\n\n\n");
}
Copy the code

The results

conclusion

Android project creation, and layout construction.