Last Updated: February 25, 2016
·
681
· jrmgx

Android Views (XML and code)

Get root view from activity

((ViewGroup)findViewById(android.R.id.content)).getChildAt(0)

Align center XML

<TextView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center"
    android:text="@string/**yourtextstring**"
/>

The last child of a Frame Layout (or Relative Layout) is the one which will appear on the top of the view (useful to do an overlay)

Animations are done thru res/drawable XML files

Spacing in List View

<ListView android:id="@+id/MyListView"
  android:layout_height="fill_parent"
  android:layout_width="fill_parent"
  android:divider="@android:color/transparent"
  android:dividerHeight="10.0sp"/>

Layout weighting

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/timeButton"
        android:layout_width="match_parent"
        android:layout_height="0px"
        android:layout_weight="10"
        android:text="X seconds" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0px"
        android:layout_weight="26" >

Rounded corner

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" android:padding="10dp">
<solid android:color="#FFFFFF"/>
   <corners
    android:bottomRightRadius="15dp"
    android:bottomLeftRadius="15dp"
    android:topLeftRadius="15dp"
    android:topRightRadius="15dp"/>
</shape>