1.Android ui 基本技术方式
<solid android:color="#ffffffff" />
<stroke android:width= "8dp" />
<corners android:radius= "8dp" />
a. Layout 定义ui 组成
a1, LinearLayout
a2, FrameLayout
a3, TableLayout
a4, GrideLayout
a5, RelativeLayout
a6, Include
a7, Fragment
b.Shape
<?xml version= "1.0" encoding ="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" ><solid android:color="#ffffffff" />
<stroke android:width= "8dp" />
<corners android:radius= "8dp" />
</shape>
c. Animation
alpha animation
<?xml version= "1.0" encoding ="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
android:fromAlpha="0.0" android:toAlpha= "1.0" android:duration ="2000" />
d.Style
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent= "android:Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style >
<!-- Application theme. -->
<style name="AppTheme" parent= "AppBaseTheme">
<!-- All customizations that are NOT specific
to a particular API-level can go here. -->
</style >
</resources>
e. Menu
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/action_settings" />
</menu>
Activity 代码中 使用Layout 产生界面可控件布局, 在AndroidManifest.xml中指定 Activity 的Theme 属性使用
Style 文件定义来产生样式,风格。具体的控件可以在布局中指明 Shape 构成背景属性。
Animation 在代码中指定定义(AnimationUtils)创建出对象,然后由控件直接(StartAnimation)使用
eg:
Animation fade = AnimationUtils.loadAnimation(this,
R.anim.fade);
findViewById(R.id. imageView1).startAnimation(fade);
2. 自定义控件技术
事件接口:base View
public boolean dispatchTouchEvent(MotionEvent ev):传递Touch事件至target view(可以是自己)。
public boolean onInterceptTouchEvent(MotionEvent ev):在ViewGroup中定义,用于拦截Touch事件的传递。
public boolean onTouchEvent(MotionEvent event): Touch事件处理函数。
public boolean onInterceptTouchEvent(MotionEvent ev):在ViewGroup中定义,用于拦截Touch事件的传递。
public boolean onTouchEvent(MotionEvent event): Touch事件处理函数。
onInterceptTouchEvent()的机制比较复杂,基本的规则是:
1.事件先路由到顶级的ViewGroup ::onInterceptTouchEvent
,若该函数返回True,将不再向下传递。
2.事件传递到一下一级 ViewGroup 或View,若函数onInterceptTouchEvent
,或者onTouchEvent 返回True,则传递终结,若False,则继续按照深度遍历方式
传递该消息。
3.若一个View接受该事件,并且有能力获取焦点,则后续消息将直接发给该View,忽略掉其它路由过程。
操纵接口: View:public
void scrollTo(int
x, int y),
View:public void scrollBy();
View:invalidate() 重绘接口
绘画接口
private void draw(Canvas canvas);