Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Android List and Adapters: adding a gradient:
- // Make the background a gradient instead of a solid color to look more awesome:
- // One way we can do it is to use an image of a gradient.
- // Or we could create a drawable in xml format.
- // Rightclick on drawable>new>drawable resource file> bg_gradient for the file name in the new window that pops up> click okay >
- // with the result, change 'selector' to 'shape' like this:
- //from this:
- <?xml version="1.0" encoding="utf-8"?>
- <selector xmlns:android="http://schemas.android.com/apk/res/android">
- </selector>
- //to this:
- <?xml version="1.0" encoding="utf-8"?>
- <shape xmlns:android="http://schemas.android.com/apk/res/android">
- </shape>
- //simple.
- //------------------------------------------------------------------------------------------
- bg_gradient.xml
- <?xml version="1.0" encoding="utf-8"?>
- <shape xmlns:android="http://schemas.android.com/apk/res/android"
- android:shape="rectangle"> <!-- this will gradient will be a rectangle-->
- <gradient
- android:startColor="#f9d34c"
- android:endColor="#f25019"
- android:angle="270"
- android:type="linear"/>
- <!-- Basically
- Color that the gradient begins with
- Color that the gradient ends with
- Angle of the gradient
- Type of gradient spread: radial, linear, etc (hit ctrl+space inside "" to see options)
- Simple.
- -->
- </shape>
- //------------------------------------------------------------------------------------------
- activity_main.xml
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:paddingLeft="@dimen/activity_horizontal_margin"
- android:paddingRight="@dimen/activity_horizontal_margin"
- android:paddingTop="@dimen/activity_vertical_margin"
- tools:context=".MainActivity"
- android:background="@drawable/bg_gradient"> <!--background @drawable -->
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="--"
- android:id="@+id/temperatureLabel"
- android:layout_centerVertical="true"
- android:layout_centerHorizontal="true"
- android:textColor="@android:color/white"
- android:textSize="150sp"/>
- <ImageView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:id="@+id/degreeImageView"
- android:layout_alignTop="@+id/temperatureLabel"
- android:layout_toRightOf="@+id/temperatureLabel"
- android:layout_toEndOf="@+id/temperatureLabel"
- android:src="@drawable/degree"
- android:layout_marginTop="50dp"/>
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="..."
- android:id="@+id/timeLabel"
- android:layout_above="@+id/degreeImageView"
- android:layout_centerHorizontal="true"
- android:textColor="#80ffffff"
- android:textSize="18sp"/>
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Alcatraz Island, CA"
- android:id="@+id/locationLabel"
- android:layout_above="@+id/timeLabel"
- android:layout_centerHorizontal="true"
- android:layout_marginBottom="60dp"
- android:textColor="@android:color/white"
- android:textSize="24sp"/>
- <ImageView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:id="@+id/iconImageView"
- android:layout_alignBottom="@+id/locationLabel"
- android:layout_alignParentLeft="true"
- android:layout_alignParentStart="true"
- android:src="@drawable/cloudy_night"/>
- <LinearLayout
- android:orientation="horizontal"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_below="@+id/temperatureLabel"
- android:layout_centerHorizontal="true"
- android:layout_marginTop="10dp"
- android:weightSum="100"
- android:id="@+id/linearLayout">
- <LinearLayout
- android:orientation="vertical"
- android:layout_width="wrap_content"
- android:layout_height="match_parent"
- android:layout_weight="50">
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="HUMIDITY"
- android:id="@+id/humidityLabel"
- android:textColor="#80FFFFFF"
- android:gravity="center_horizontal"/>
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="--"
- android:id="@+id/humidityValue"
- android:textColor="@android:color/white"
- android:textSize="24sp"
- android:gravity="center_horizontal"/>
- </LinearLayout>
- <LinearLayout
- android:orientation="vertical"
- android:layout_width="wrap_content"
- android:layout_height="match_parent"
- android:layout_weight="50">
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="RAIN/SNOW?"
- android:id="@+id/precipLabel"
- android:textColor="#80ffffff"
- android:gravity="center_horizontal"/>
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="--"
- android:id="@+id/precipValue"
- android:textColor="@android:color/white"
- android:textSize="24sp"
- android:gravity="center_horizontal"/>
- </LinearLayout>
- </LinearLayout>
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Getting current weather..."
- android:id="@+id/summaryLabel"
- android:layout_below="@+id/linearLayout"
- android:layout_centerHorizontal="true"
- android:layout_margin="40dp"
- android:textColor="@android:color/white"
- android:textSize="18sp"
- android:gravity="center_horizontal"/>
- <ImageView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:id="@+id/refreshImageView"
- android:layout_alignParentTop="true"
- android:layout_centerHorizontal="true"
- android:src="@drawable/refresh"/>
- <ProgressBar
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:id="@+id/progressBar"
- android:layout_alignParentTop="true"
- android:layout_centerHorizontal="true"
- android:layout_alignBottom="@+id/refreshImageView"/>
- <LinearLayout
- android:orientation="horizontal"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_alignParentBottom="true"
- android:layout_alignParentLeft="true"
- android:layout_alignParentStart="true">
- <Button
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="HOURLY"
- android:id="@+id/hourlyButton"
- android:layout_weight="1"
- android:background="#40ffffff"
- android:textColor="#ffffffff"/>
- <Button
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="7 DAY"
- android:id="@+id/dailyButton"
- android:layout_weight="1"
- android:background="#40ffffff"
- android:textColor="#ffffffff"
- android:layout_marginLeft="2dp"/>
- </LinearLayout>
- </RelativeLayout>
- //Also added some space between the two buttons with: android:layout_marginLeft="2dp
- // Simple.
- // https://teamtreehouse.com/library/android-lists-and-adapters/standard-listviews/adding-a-gradient
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement