Advertisement
yo2man

Standard ListViews: updating the main layout

Jul 13th, 2015
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 7.32 KB | None | 0 0
  1. // Standard ListViews: updating the main layout
  2.  
  3. //Email, twitter, facebook, yik yak all display data in some kind of a list. Sometimes its text, sometimes its images, etc
  4. // List is so commonly used that we really wanna understand it in detail!
  5.  
  6. // The basic idea is that we have some list of data stored as an array of collection of objects.
  7. // We create a view, a layout file of how we want it to be displayed.
  8. // And then we use an adaptor(a special JAVA class) to prepare the data and adapt it for display.
  9.  
  10. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  11.                xmlns:tools="http://schemas.android.com/tools"
  12.                android:layout_width="match_parent"
  13.                android:layout_height="match_parent"
  14.                android:paddingLeft="@dimen/activity_horizontal_margin"
  15.                android:paddingRight="@dimen/activity_horizontal_margin"
  16.                android:paddingTop="@dimen/activity_vertical_margin"
  17. <!-- got rid of default android:paddingBottom to put the buttons all the way at the bottom-->
  18.                 tools:context=".MainActivity"
  19.                 android:background="#FFFC970b">
  20.  
  21.     <TextView
  22.        android:layout_width="wrap_content"
  23.        android:layout_height="wrap_content"
  24.        android:text="--"
  25.        android:id="@+id/temperatureLabel"
  26.        android:layout_centerVertical="true"
  27.        android:layout_centerHorizontal="true"
  28.        android:textColor="@android:color/white"
  29.        android:textSize="150sp"/>
  30.  
  31.     <ImageView
  32.        android:layout_width="wrap_content"
  33.        android:layout_height="wrap_content"
  34.        android:id="@+id/degreeImageView"
  35.        android:layout_alignTop="@+id/temperatureLabel"
  36.        android:layout_toRightOf="@+id/temperatureLabel"
  37.        android:layout_toEndOf="@+id/temperatureLabel"
  38.        android:src="@drawable/degree"
  39.        android:layout_marginTop="50dp"/>
  40.  
  41.     <TextView
  42.        android:layout_width="wrap_content"
  43.        android:layout_height="wrap_content"
  44.        android:text="..."
  45.        android:id="@+id/timeLabel"
  46.        android:layout_above="@+id/degreeImageView"
  47.        android:layout_centerHorizontal="true"
  48.        android:textColor="#80ffffff"
  49.        android:textSize="18sp"/>
  50.  
  51.     <TextView
  52.        android:layout_width="wrap_content"
  53.        android:layout_height="wrap_content"
  54.        android:text="Alcatraz Island, CA"
  55.        android:id="@+id/locationLabel"
  56.        android:layout_above="@+id/timeLabel"
  57.        android:layout_centerHorizontal="true"
  58.        android:layout_marginBottom="60dp"
  59.        android:textColor="@android:color/white"
  60.        android:textSize="24sp"/>
  61.  
  62.     <ImageView
  63.        android:layout_width="wrap_content"
  64.        android:layout_height="wrap_content"
  65.        android:id="@+id/iconImageView"
  66.        android:layout_alignBottom="@+id/locationLabel"
  67.        android:layout_alignParentLeft="true"
  68.        android:layout_alignParentStart="true"
  69.        android:src="@drawable/cloudy_night"/>
  70.  
  71.     <LinearLayout
  72.        android:orientation="horizontal"
  73.        android:layout_width="match_parent"
  74.        android:layout_height="wrap_content"
  75.        android:layout_below="@+id/temperatureLabel"
  76.        android:layout_centerHorizontal="true"
  77.        android:layout_marginTop="10dp"
  78.        android:weightSum="100"
  79.        android:id="@+id/linearLayout">
  80.  
  81.         <LinearLayout
  82.            android:orientation="vertical"
  83.            android:layout_width="wrap_content"
  84.            android:layout_height="match_parent"
  85.            android:layout_weight="50">
  86.  
  87.             <TextView
  88.                android:layout_width="match_parent"
  89.                android:layout_height="wrap_content"
  90.                android:text="HUMIDITY"
  91.                android:id="@+id/humidityLabel"
  92.                android:textColor="#80FFFFFF"
  93.                android:gravity="center_horizontal"/>
  94.  
  95.             <TextView
  96.                android:layout_width="match_parent"
  97.                android:layout_height="wrap_content"
  98.                android:text="--"
  99.                android:id="@+id/humidityValue"
  100.                android:textColor="@android:color/white"
  101.                android:textSize="24sp"
  102.                android:gravity="center_horizontal"/>
  103.         </LinearLayout>
  104.  
  105.         <LinearLayout
  106.            android:orientation="vertical"
  107.            android:layout_width="wrap_content"
  108.            android:layout_height="match_parent"
  109.            android:layout_weight="50">
  110.  
  111.             <TextView
  112.                android:layout_width="match_parent"
  113.                android:layout_height="wrap_content"
  114.                android:text="RAIN/SNOW?"
  115.                android:id="@+id/precipLabel"
  116.                android:textColor="#80ffffff"
  117.                android:gravity="center_horizontal"/>
  118.  
  119.             <TextView
  120.                android:layout_width="match_parent"
  121.                android:layout_height="wrap_content"
  122.                android:text="--"
  123.                android:id="@+id/precipValue"
  124.                android:textColor="@android:color/white"
  125.                android:textSize="24sp"
  126.                android:gravity="center_horizontal"/>
  127.         </LinearLayout>
  128.     </LinearLayout>
  129.  
  130.     <TextView
  131.        android:layout_width="wrap_content"
  132.        android:layout_height="wrap_content"
  133.        android:text="Getting current weather..."
  134.        android:id="@+id/summaryLabel"
  135.        android:layout_below="@+id/linearLayout"
  136.        android:layout_centerHorizontal="true"
  137.        android:layout_margin="40dp"
  138.        android:textColor="@android:color/white"
  139.        android:textSize="18sp"
  140.        android:gravity="center_horizontal"/>
  141.  
  142.     <ImageView
  143.        android:layout_width="wrap_content"
  144.        android:layout_height="wrap_content"
  145.        android:id="@+id/refreshImageView"
  146.        android:layout_alignParentTop="true"
  147.        android:layout_centerHorizontal="true"
  148.        android:src="@drawable/refresh"/>
  149.  
  150.     <ProgressBar
  151.        android:layout_width="wrap_content"
  152.        android:layout_height="wrap_content"
  153.        android:id="@+id/progressBar"
  154.        android:layout_alignParentTop="true"
  155.        android:layout_centerHorizontal="true"
  156.        android:layout_alignBottom="@+id/refreshImageView"/>
  157.  
  158.     <LinearLayout
  159.        android:orientation="horizontal"
  160.        android:layout_width="match_parent"
  161.        android:layout_height="wrap_content"
  162.        android:layout_alignParentBottom="true"
  163.        android:layout_alignParentLeft="true"
  164.        android:layout_alignParentStart="true">
  165.  
  166.  
  167. // add two buttons to the bottom
  168.         <Button
  169.            android:layout_width="match_parent"
  170.            android:layout_height="wrap_content"
  171.            android:text="HOURLY"
  172.            android:id="@+id/hourlyButton"
  173.            android:layout_weight="1"
  174.            android:background="#40ffffff"
  175.            android:textColor="#ffffffff"/>
  176.  
  177.         <Button
  178.            android:layout_width="match_parent"
  179.            android:layout_height="wrap_content"
  180.            android:text="7 DAY"
  181.            android:id="@+id/dailyButton"
  182.            android:layout_weight="1"
  183.            android:background="#40ffffff"
  184.            android:textColor="#ffffffff"/>
  185.     </LinearLayout>
  186. </RelativeLayout>
  187.  
  188.  
  189. // https://teamtreehouse.com/library/android-lists-and-adapters/standard-listviews/updating-the-main-layout
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement