Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2087388
  • 博文数量: 413
  • 博客积分: 10926
  • 博客等级: 上将
  • 技术积分: 3862
  • 用 户 组: 普通用户
  • 注册时间: 2006-01-09 18:14
文章分类

全部博文(413)

文章存档

2015年(5)

2014年(1)

2013年(5)

2012年(6)

2011年(138)

2010年(85)

2009年(42)

2008年(46)

2007年(26)

2006年(59)

分类: 嵌入式

2010-06-10 17:03:19

  1. Documents:
    • User Interface
      http://developer.android.com/guide/topics/ui/index.html
    • How Android Draws Views
      http://developer.android.com/guide/topics/ui/how-android-draws.html
    • Customize Widgets
      http://developer.android.com/guide/topics/ui/custom-components.html
    • Handle UI Events
      http://developer.android.com/guide/topics/ui/ui-events.html
    • Style & Theme
      http://developer.android.com/guide/topics/ui/themes.html
    • AdapterView (ListView, Spinner, Gallery)
      http://developer.android.com/guide/topics/ui/binding.html
    • Supporting Multiple Screens
      http://developer.android.com/guide/practices/screens_support.html
    • Creating Reusable UI Components
      http://developer.android.com/resources/articles/layout-tricks-reuse.html
    • UI Framework Changes in Android 1.5 / 1.6
      • http://developer.android.com/resources/articles/ui-1.5.html
      • http://developer.android.com/resources/articles/ui-1.6.html
    • xxx
  2. SDK
    All view are defined in sdk/platforms/android-x/data/res:
    layout: The layour of all view
    values: string items, styles (styles.xml) , attrs (attrs.xml)
  3. Summary
    "Widgets" are views that provide a visual (and interactive) elements for the screen, such as a button, text field, checkbox, or just an image.

    Android provides a number of ready-made views that you can use to design and organize your layout. You can also subclass the View and ViewGroup classes (or existing subclasses) to create your own widgets and layouts and apply them to your activity layout.

    There are many types of views and view groups, each of which is a descendant of the View class. View can be divided into Widget and Layout.
    A View object is a data structure whose properties store the layout parameters and content for a specific rectangular area of the screen. A View object handles its own measurement,and key/gesture events.
  4. UI design tips
    1. ANR (Android No Responding dialog)
      In Android, application responsiveness is monitored by the Activity Manager and Window Manager system services. Android will display the ANR dialog for a particular application when it detects one of the following conditions:
      • No response to an input event (e.g. key press, screen touch) within 5 seconds
      • BroadcastReceiver hasn't finished executing within 10 seconds
    2. xxx
  5. View
    The base class of all widgets and ViewGroup(Layout)
    1. setTag
      Bind private data to the view.
    2. setVisibility
      Visible: view.setVisibility(View.VISIBLE);
      Invisible: view.setVisibility(View.INVISIBLE);
      Invisible and discard the space: view.setVisibility(View.GONE);
    3. id
      The syntax for an ID, inside an XML tag is: "@[+][package:]type:name"
      The at-symbol (@) at the beginning of the string indicates that the XML parser should parse and expand the rest of the ID string and identify it as an ID resource.
      The plus-symbol (+) means that this is a new resource name that must be created and added to our resources (in the R.java file). There are a number of other ID resources that are offered by the Android framework. When referencing an Android resource ID, you do not need the plus-symbol, but must add the android package namespace, like so: android:id="@android:id/empty".

      An ID need not be unique throughout the entire tree, but it should be unique within the part of the tree you are searching (which may often be the entire tree, so it's best to be completely unique when possible).
    4. padding & margin
      Padding can be used to offset the content of the view. The padding space is belong of the View, while the space of margin is not. Padding means set extra space from contensts, while margin means add extra space from UI component.
    5. size
      The first pair is known as measured width and measured height. These dimensions define how big a view wants to be within its parent.

      The second pair is simply known as width and height, or sometimes drawing width and drawing height. These dimensions define the actual size of the view on screen, at drawing time and after layout. These values may, but do not have to, be different from the measured width and height.
    6. requestFocus
      Make the control get focus.
    7. xxx
  6. SurfaceView
    Provides a dedicated drawing surface embedded inside of a view hierarchy. One of the purposes of this class is to provide a surface in which a secondary thread can render into the screen.
  7. GLSurfaceView
  8. RemoteViews
    A class that describes a view hierarchy that can be displayed in another process. The hierarchy is inflated from a layout resource file, and this class provides some basic operations for modifying the content of the inflated hierarchy.
  9. Button
    • Button
      • Set style
        buttonStyleXXX defined in android.R.attr, you can apply button style as
        style="?android:attr/buttonStyleXXX", such as small button:

      • xxx
    • ToggleButton
    • RadioButton + RadioGroup
    • ImageButton
    • xxx
  10. Progress
    • ProgressBar
      • horizental style
        style="?android:attr/progressBarStyleHorizontal"

    • ProgressDialog
    • SeekBar
      Like ProgressBar but with a draggable thumb, user can touch the thumb and drag left or right to set the progress.
    • RatingBar
      Is extension of SeekBar that shows rating in stars.
    • Issue:
      • Refresh
        When Activity is in background, the progress can be increased but the ProgressBar won't be refreshed. Later if you switch the Activity to foreground, the ProgressBar will not be refreshed if you don't call setProgress to set a new value, even if you call ProgressBar.invalidate(). i.e. When progress reaches 100 when the Activity is in background, then switch the Activity to foreground, you will find the ProgressBar is not freshed to 100.
        Solution: call progressBar.setSaveEnable(false), or set android:saveEnabled="false" in layout xml file.
      • xxx
    • xxx
  11. ImageView
  12. ListView
    When you add/remove line(s) to/from Adapter, you can call Adapter.notifyDataSetChanged() to notify AdapterView to refresh, but if you only change the contents of existing row(s), that API doesn't take effective.
    • Common ListView
    • Single Choice ListView
    • Multiple Choice ListView
    • Expandable Choice ListView (
    • Customized ListView containing complex item tow
  13. Text View
    • TextView
      • Set preference group style with 'listSeparatorTextViewStyle'
            ...
            style="?android:attr/listSeparatorTextViewStyle"
            .... 
        />
      • set color
        TextView.setTextColor(ColorStateList.valueOf(Color.WHITE));
        rather than TextView.setTextColor(Color.WHITE);
      • xxx
    • EditText
      • Attributes
        1. singleLine
          Make sure only one line can be shown, and user can only input one line' contents.
        2. lines
          Make sure only the specified lines' contents can be shown at most, but user can input more lines' contents.
      • For the following layout, EditText will be stretched, and Button is aligned out of screen.
            android:layout_height="wrap_content"
            android:stretchColumns="0"
           
                            android:singleLine="true"
                    android:ellipsize="middle"
                    android:text="aaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbccccccccc" />
               
      • xxx
    • AutoCompleteTextView
      http://developer.android.com/resources/tutorials/views/hello-autocomplete.html
    • xxx
  14. ScrollView

    • Add ScrollBar
      Add ScrollView out of target view, i.e

          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          >


          android:orientation="vertical"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent" />


              android:id="@+id/headertable"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:stretchColumns="1"
              android:collapseColumns="2"/>

      android:layout_width="fill_parent"
              android:layout_height="wrap_content"
      >
      >

    • Change scroll bar style

      ......
         
      android:scrollbarTrackVertical="@drawable/scrollbar_vertical_track"
         
      android:scrollbarThumbVertical="@drawable/scrollbar_vertical_thumb"
      />
    • ScrollBar Style

      ...
      android:scrollBarStyle=xxx"
      />


      if scroll bar overwrap contents within the scrollview, you can add android:scrollbarStype="insideInset" to ScrollView, i.e.

          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:scrollbarStype="insideInset"
          >


      or set dynamic in source code as:
      findViewById(R.id.scroll_view_id).setScrollBarStyle(View.SCROLLBARS_INSIDE_INSET);
    • xxx

  15. CheckBox

    • Display as a star and can be checked
          ....
          style="?android:attr/starStyle"
          ... />
    • xxx
  16. DatePicker & TimePicker (vs. DatePickerDialog & TimePickerDialog) &
  17. Spinner
    Spinner s1 = (Spinner) findViewById(R.id.spinner1);
            ArrayAdapter adapter = ArrayAdapter.createFromResource(
                    this, R.array.colors, android.R.layout.simple_spinner_item);
    //Must set dropdown view resource for Spinner       adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            s1.setAdapter(adapter);
  18. PreferenceScreen
    • PreferenceCateory
      • Preference
      • CheckBoxPreference
      • EditTextPreference
      • ListPreference
      • PreferenceScreen (To open a new activity)
        • CheckBoxPreference .....
        • intent
        • xxx
      • xxx
    • xxx
  19. GridView
  20. Gallery
  21. TabHost
  22. ViewAnimator
    • ViewFlipper
      Animate between two or more views that have been added to it. Only one child is shown at a time. If requested, can automatically flip between each child at a regular interval.
    • ViewSwitcher
      Switches between two views, and has a factory from which these views are created.  A ViewSwitcher can only have two child views, of which only one is shown at a time.
      • ImageSwitcher

        Sample:
        mSwitcher.setFactory(this);
        mSwitcher.setInAnimation(AnimationUtils.loadAnimation(this,
                        android.R.anim.fade_in));
        mSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this,
                        android.R.anim.fade_out));
        ......
        mSwitcher.setImageResource(xxx); //Change image
      • xxx
    • TextSwitcher
      ViewSwitcher contains only children of type TextView. A TextSwitcher is useful to animate a label on screen. Whenever setText(CharSequence) is called, TextSwitcher animates the current text out and animates the new text in.

      Sample: Search 'TextSwitcher1.java' in Google, or sample ApiDemo in Android sdk: Api Demos > Views > TextSwitcher
    • xxx
  23. Customize View
    • Implement class MyView that inherits from View
      • onDraw
      • onKeyXXX
      • onTouchXXX
      • xxx
    • Create an object of MyView, you can add the object to ViewGroup
    • call Activity.setContentView to display the View/ViewGroup
    • You can define yourown attributes (styleable properties)
      You can define new attributes of yourown, just as attrubites 'android:text', 'android:textColor' of widget TextView.
      (Sample: ApiDemo. Related files: LabelView.java, attrs.xml, custom_view_1.xml, LabelView.java)
    • xxx
  24. ActionBar
    http://developer.android.com/guide/topics/ui/actionbar.html
  25. Chronometer
    Class that implements a simple timer.
  26. SearchView
    A widget that provides a user interface for the user to enter a search query and submit a request to a search provider.
  27. VideoView
    Displays a video file.
  28. WebView
    1. load uri
      1. load from asset
        webView.loadUrl("file:///android_asset/my_web.html");
      2. load from raw
        webView.loadUrl("android.resource://" + getPackageName() + "/" + R.raw.my_web_file);
      3. file:///android_res.
    2. Q&A
      1. Enable JavaScript
        webSettings.setJavaScriptEnabled(true);
      2. Enable alert() & console.log() in JavaScript
        Invoke the following interface before loadurl.
        webview.setWebChromeClient(new WebChromeClient()
        {
            Override
            public boolean onJsAlert(WebView view, String url, String message, JsResult result)
            {
                return super.onJsAlert(view, url, message, result);
            }
        });
      3. Call method in Javascript
        mWebView.getSettings().setJavaScriptEnabled(true); 
        mWebView.loadUrl("file:///android_asset/demo.html");    mWebView.loadUrl("javascript:fillContent()"); 


  29. Others
    • AccessibilityService
      Runs in the background and receives callbacks by the system when AccessibilityEvents are fired. for example, the focus has changed, a button has been clicked, etc.
    • xxx
  30. xxx
阅读(2034) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~