Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Android UI part I

Android UI part I

Covers the basics of Android UI development

Alexey Buzdin

October 01, 2014
Tweet

More Decks by Alexey Buzdin

Other Decks in Programming

Transcript

  1. src/**/MainActivity.java public class MainActivity extends Activity { ! @Override protected

    void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } }
  2. supports consistent navigation and view switching (tabs or drop-down lists)

    http://developer.android.com/guide/topics/ui/actionbar.html ActionBar dedicated space for app identity and user's location makes important actions accessible (such as Search)
  3. An action bar that includes the [1] app icon, [2]

    two action items, and [3] action overflow.
  4. View is java class a visual application component on a

    screen http://developer.android.com/reference/android/view/View.html onMeasure() onLayout() onDraw() with methods:
  5. Example @Override protected void onCreate(Bundle state) { super.onCreate(state); TextView view

    = new TextView(this); view.setText("Hello World"); setContentView(view); }
  6. Context access to application-specific resources and classes for launching activities,

    broadcasting and receiving intents, etc. access to up-calls for application-level operations
  7. Example @Override protected void onCreate(Bundle state) { super.onCreate(state); mapView =

    new MapView(this); mapView.onCreate(state); setContentView(mapView); }
  8. <LinearLayout xmlns:android="http:// schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> ! < android:layout_width="wrap_content" android:layout_height="wrap_content"

    android:text=“1"/> ! …2 more buttons.. ! </ res https://gist.github.com/LArchaon/4ea1eaa89c21ceccda10 android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_height="wrap_content"
  9. in Activity Layout resource from res/ @Override protected void onCreate(Bundle

    state) { super.onCreate(state); setContentView(R.layout.main); }
  10. @Override protected void onCreate(Bundle state) { super.onCreate(state); View view =

    LayoutInflater.from(this) .inflate(R.layout.main, null); setContentView(view); } same as
  11. LayoutInflater 1. fill (a balloon, tyre, or other expandable structure)

    with air or gas so that it becomes distended. 2. increase (something) by a large or excessive amount. View view = LayoutInflater.from(this) .inflate(R.layout.activity_main, null); inflate! /ɪnˈfleɪt/! verb
  12. LayoutInflater 1. fill (a balloon, tyre, or other expandable structure)

    with air or gas so that it becomes distended. 2. increase (something) by a large or excessive amount. View view = LayoutInflater.from(this) .inflate(R.layout.activity_main, null); inflate! /ɪnˈfleɪt/! verb Fill View from XML
  13. @Override protected void onCreate(Bundle state) { super.onCreate(state); View view =

    LayoutInflater.from(this) .inflate(R.layout.main, null); Button button = (Button) view.findViewById(R.id.button); button.setText("Button"); setContentView(view); } View.findViewById
  14. @Override protected void onCreate(Bundle state) { super.onCreate(state); setContentView(R.layout.main); Button button

    = (Button) findViewById(R.id.button); button.setText("Button"); } Activity.findViewById
  15. <LinearLayout ….. android:orientation="horizontal" android:weightSum="2"> ! <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="1"/>

    ! <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="2"/> ! </LinearLayout>
  16. <LinearLayout ….. android:orientation="horizontal" android:weightSum="3"> ! <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="2" android:text="1"/>

    ! <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="2"/> ! </LinearLayout>
  17. <LinearLayout ….… android:weightSum="5"> ! <Button ….. android:layout_weight="1" android:text="1"/> <LinearLayout android:layout_width="0dp"

    android:layout_height="wrap_content" android:layout_weight=“3" android:orientation="vertical"> </LinearLayout> ! <Button … android:layout_weight="1" android:text="2"/> ! </LinearLayout>
  18. <LinearLayout …… android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <Button android:layout_width="0dp" android:layout_height="wrap_content"

    android:layout_weight="0.5" android:text="3"/> ….. Button with text 4 …… </LinearLayout> ! <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="5"/> </LinearLayout> https://gist.github.com/LArchaon/b0ef20c1395c3b884b47
  19. <RelativeLayout …. > <Button …. android:id="@+id/A" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" /> <Button

    …. android:id="@+id/F" android:layout_alignParentRight="true"/> <LinearLayout …. android:id="@+id/container" android:layout_toRightOf="@+id/A" android:layout_toLeftOf="@+id/F" android:weightSum="3"> <Button android:text="B" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1"/> …. Buttons C and D ….. </LinearLayout> …. Button E ….. </RelativeLayout> https://gist.github.com/LArchaon/b6842ad6f4eadbfac012
  20. Configuration qualifiers en, fr, en-rUS, fr-rFR, fr-rCA Language and region

    mcc310, mcc310-mnc004 Mobile country code Screen size small, normal, large, xlarge Orientation land, port Screen density ldpi, mdpi, hdpi, nodpi
  21. Do not use hard-coded values in your application code (num,

    strings) Use wrap_content, fill_parent, or the dp unit for layout dimensions Test Your Application on Multiple Screens !
  22. Q&A