jamesmuskett / newWeather

my 1st go at an android app
0 stars 0 forks source link

Your first custom (compound) view! #9

Closed vaughandroid closed 10 years ago

vaughandroid commented 10 years ago

Make a custom view from some of the views already in the WeatherFragment. AKA a "compound view".

Approach 1 (e.g. PriceLabelView in the LateRooms project)

  1. Move the views into a new XML file. e.g. weather_view.xml The top-level XML tag should be a <merge/> tag.
  2. Create a new class which extends View. e.g. com.jmuskett.newweather.WeatherView
  3. Inside the constructor for your new view, do LayoutInflater.from(context).inflate(R.layout.weather_view, this); to inflate the XML file make it the content of your View.
  4. Include the layout inside another view by adding a <com.jmuskett.newweather.WeatherView/> element.

Approach 2 (e.g. ProgressView / progress.xml in the LR project)

  1. Create a new class which extends ViewGroup, or more likely one of its subclasses like LinearLayout. e.g. com.jmuskett.newweather.WeatherView2
  2. Move the views into a new XML file. e.g. weather_view2.xml The top-level XML tag should be <com.jmuskett.newweather.WeatherView/>
  3. Include the layout inside another view by adding an <include/> element, with the android:layout value set to the name of your new XML file - e.g. "@layout/weather_view2"

Questions:

vaughandroid commented 10 years ago

Scrapping this for a more incremental approach!