Andriod5.0 新特性

1、阴影:设置elevation 或translationZ属性

<TextView
        android:id="@+id/tv_cicle"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:background="@drawable/shape_oval"
        android:elevation="@dimen/activity_horizontal_margin"
        android:translationZ="@dimen/activity_horizontal_margin"
        android:text="Hello World!" />

2、裁剪:

1)圆形

TextView textView = (TextView) findViewById(R.id.tv_cicle);
ViewOutlineProvider vop = new ViewOutlineProvider() {
    @Override
    public void getOutline(View view, Outline outline) {
        outline.setOval(0,0 , view.getWidth(), view.getHeight());
    }
};
textView.setOutlineProvider(vop);
textView.setClipToOutline(true);

2)矩形

TextView tv_round = (TextView) findViewById(R.id.tv_round)
ViewOutlineProvider vop1 = new ViewOutlineProvider() {
    @Override
    public void getOutline(View view, Outline outline) {
        outline.setRoundRect(0, 0 , view.getWidth(), view.getHeight(), 25);
    }
};
tv_round.setOutlineProvider(vop1);
tv_round.setClipToOutline(true);

3、Tint颜色合成模式

1)创建图片: bitmap_tint.xml

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@mipmap/ring"
    android:tintMode="multiply"
    android:tint="#e324542"
   />

2)创建selector :bitmap_selector.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/bitmap_selector" android:state_pressed="true" />
    <item android:drawable="@mipmap/ring" />
</selector>

3)设置到ImageView里

<ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/bitmap_selector"
        android:id="@+id/imageView"
        android:layout_below="@+id/tv_cicle"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginLeft="32dp"
        android:layout_marginStart="32dp"
        android:layout_marginTop="134dp" />

4、使用vector绘制心形,m移动到,c贝塞尔曲线

<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="264dp"
    android:height="264dp"
    android:viewportHeight="600"
    android:viewportWidth="600">
    <path
        android:fillColor="#580f23"
        android:pathData="M20.5,9.5
                        c-1.955,0,-3.83,1.268,-4.5,3
                        c-0.67,-1.732,-2.547,-3,-4.5,-3
                        C8.957,9.5,7,11.432,7,14
                        c0,3.53,3.793,6.257,9,11.5
                        c5.207,-5.242,9,-7.97,9,-11.5
                        C25,11.432,23.043,9.5,20.5,9.5z" />
</vector>

5、Button样式动画:

在xml定义

<Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New Button"
        android:id="@+id/button2"
        android:background="?android:attr/selectableItemBackground"
        android:layout_centerVertical="true"
        android:layout_alignLeft="@+id/button"
        android:layout_alignStart="@+id/button" />

    ------------------------------------------------------------------------------------------

在activity定义

Button button = (Button) findViewById(R.id.button3);
        Animator animator = ViewAnimationUtils.createCircularReveal(button, button.getWidth()/2, button.getHeight()/2, button.getWidth(), button.getHeight() )
        animator.setDuration(1000);
        animator.setInterpolator(new LinearInterpolator());
        animator.start();

Button button4 = (Button) findViewById(R.id.button4);
        button4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Animator animator = ViewAnimationUtils.createCircularReveal(view, 0, view.getHeight(),0, (float)Math.hypot(view.getWidth(), view.getHeight()));
                animator.setDuration(1000);
                animator.setInterpolator(new LinearInterpolator());
                animator.start();
            }
        });

6、Path动画

ImageView imageView = (ImageView) findViewById(R.id.iv_test);
 Path path = new Path();
 path.moveTo(100,100);
 path.quadTo(1000, 300, 300, 700);

 ObjectAnimator animator = ObjectAnimator.ofFloat(imageView, View.X, View.Y, path);
 Path p = new Path();
 p.lineTo(0.6f, 0.9f);
 p.lineTo(0.75f, 0.2f);
 p.lineTo(1f, 1f);
 animator.setInterpolator(new PathInterpolator(p));
 animator.setDuration(3000);
 animator.start();

7、Selector选择器里的属性动画

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@color/control_highlight_blue_grey">
        <set>
            <objectAnimator android:propertyName="translationZ"
                            android:duration="200"
                            android:valueTo="20dp"
                            android:valueType="floatType"/>
            <objectAnimator android:propertyName="scaleX"
                            android:duration="200"
                            android:valueTo="0.5"
                            android:valueType="floatType"/>
            <objectAnimator android:propertyName="scaleY"
                            android:duration="200"
                            android:valueTo="0.5"
                            android:valueType="floatType"/>
        </set>
    </item>
    <item android:state_enabled="true" android:state_pressed="false" android:drawable="@color/button_normal_blue_grey">
        <set>
            <objectAnimator android:propertyName="translationZ"
                            android:duration="200"
                            android:valueTo="0"
                            android:valueType="floatType"/>
            <objectAnimator android:propertyName="scaleX"
                            android:duration="200"
                            android:valueTo="1"
                            android:valueType="floatType"/>
            <objectAnimator android:propertyName="scaleY"
                            android:duration="200"
                            android:valueTo="1"
                            android:valueType="floatType"/>
        </set>
    </item>
</selector>

8、CheckBox属性动画,图片轮播动画

<?xml version="1.0" encoding="utf-8"?>
<animated-selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/pressed" android:drawable="@drawable/btn_check_15" android:state_pressed="true"/>
    <item android:id="@+id/normal"  android:drawable="@drawable/btn_check_0"/>
    <transition android:fromId="@+id/normal" android:toId="@+id/pressed">
        <animation-list>
            <item android:duration="20" android:drawable="@drawable/btn_check_0"/>
            <item android:duration="20" android:drawable="@drawable/btn_check_1"/>
            <item android:duration="20" android:drawable="@drawable/btn_check_2"/>
            <item android:duration="20" android:drawable="@drawable/btn_check_3"/>
            <item android:duration="20" android:drawable="@drawable/btn_check_4"/>
            <item android:duration="20" android:drawable="@drawable/btn_check_5"/>
            <item android:duration="20" android:drawable="@drawable/btn_check_6"/>
            <item android:duration="20" android:drawable="@drawable/btn_check_7"/>
            <item android:duration="20" android:drawable="@drawable/btn_check_8"/>
            <item android:duration="20" android:drawable="@drawable/btn_check_9"/>
            <item android:duration="20" android:drawable="@drawable/btn_check_10"/>
            <item android:duration="20" android:drawable="@drawable/btn_check_12"/>
            <item android:duration="20" android:drawable="@drawable/btn_check_13"/>
            <item android:duration="20" android:drawable="@drawable/btn_check_14"/>
            <item android:duration="20" android:drawable="@drawable/btn_check_15"/>
        </animation-list>
    </transition>
</animated-selector>

9、矢量动画

1)先定义Paht动画

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <objectAnimator
            android:duration="3000"
            android:propertyName="pathData"
            android:valueFrom="M67,750 L500,0 500,0 933,750 67,750        M146,853 A 0.1,500 0 0 1 146,148 M146,148 A 500,0.1 0 0 1 851,148  M851,148 A 0.1,500 0 0 1 851,853 M851,853 A 500,0.1 0 0 1 146,853"
            android:valueTo="M147,853 L147,147 853,147 853,853 147,853    M146,853 A 0.1,500 0 0 1 146,148 M146,148 A 500,0.1 0 0 1 851,148  M851,148 A 0.1,500 0 0 1 851,853 M851,853 A 500,0.1 0 0 1 146,853"
            android:valueType="pathType" />

    <objectAnimator
            android:startOffset="3000"
            android:duration="3000"
            android:propertyName="pathData"
            android:valueFrom="M147,853 L147,147 853,147 853,853 147,853    M147,853 A 0.1,500 0 0 1 147,147 M147,147 A 500,0.1 0 0 1 853,147  M853,147 A 0.1,500 0 0 1 853,853 M851,853 A 500,0.1 0 0 1 147,853"
            android:valueTo="M147,853 L147,147 853,147 853,853 147,853      M147,853 A 500,500 0 0 1 147,147 M147,147 A 500,500 0 0 1 853,147  M853,147 A 500,500 0 0 1 853,853 M853,853 A 500,500 0 0 1 147,853"
            android:valueType="pathType" />
</set>

2)定义旋转动画

<?xml version="1.0" encoding="utf-8"?>
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="6000"
    android:propertyName="rotation"
    android:valueFrom="0"
    android:valueTo="0" />

3)动画合成

<?xml version="1.0" encoding="utf-8"?>
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
                 android:drawable="@drawable/vector_drawable" >
    <target
            android:name="vector"
            android:animation="@anim/vector_anim" />

    <target
            android:name="rotation"
            android:animation="@anim/vector_rotation" />
</animated-vector>

10、页面转场动画

public class TransitionsActivity extends Activity implements View.OnClickListener {
    Button bt1,bt2,bt3,bt4;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
        //getWindow().setAllowEnterTransitionOverlap(true);
        //getWindow().setAllowReturnTransitionOverlap(true);
        setContentView(R.layout.activity_transitions);


        bt1 = (Button) findViewById(R.id.bt1);
        bt2 = (Button) findViewById(R.id.bt2);
        bt3 = (Button) findViewById(R.id.bt3);
        bt4 = (Button) findViewById(R.id.bt4);

        bt1.setOnClickListener(this);
        bt2.setOnClickListener(this);
        bt3.setOnClickListener(this);
        bt4.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        Intent intent = null;
        Transition transition = null;
        switch (v.getId()) {
            case R.id.bt1:
                //
                transition = new Explode();
                intent = new Intent(TransitionsActivity.this, ExplodeActivity.class);
                break;
            case R.id.bt2:
                //淡入淡出
                transition = new Fade();
                intent = new Intent(TransitionsActivity.this, FadeActivity.class);
                break;
            case R.id.bt3:
                //滑动
                transition = new Slide();
                intent = new Intent(TransitionsActivity.this, SlideActivity.class);
                break;
            case R.id.bt4:
                break;

        }

        if (v.getId() != R.id.bt4) {
            transition.setDuration(1000);
            getWindow().setEnterTransition(transition);
            getWindow().setExitTransition(transition);
            getWindow().setReturnTransition(transition);
            getWindow().setReenterTransition(transition);
            startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(TransitionsActivity.this).toBundle());
        } else {
            TransitionSet set = new TransitionSet();
            set.addTransition(new Explode());
            set.addTransition(new Fade());
            set.setDuration(1000);
            getWindow().setReturnTransition(set);
            getWindow().setReenterTransition(set);
            getWindow().setEnterTransition(set);
            getWindow().setExitTransition(set);

            bt4.setTransitionName("bt4");
            TransitionSet transitionSet = new TransitionSet();
            transitionSet.addTransition(new ChangeTransform());
            transitionSet.addTransition(new ChangeBounds());
            transitionSet.addTarget("bt4");
            transitionSet.setDuration(1000);
            getWindow().setSharedElementEnterTransition(transitionSet);
            getWindow().setSharedElementExitTransition(transitionSet);
            getWindow().setSharedElementReturnTransition(transitionSet);
            getWindow().setSharedElementReenterTransition(transitionSet);
            intent = new Intent(this, ShareActivity.class);

            ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(this, bt4, "bt4");
            startActivity(intent, options.toBundle());

        }
    }
}

11、下拉刷新SwipeRefreshLayout

1)布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="150dp"
        android:background="#03A9F4"/>


    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/refresh"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler"
            android:padding="5dp"
            android:background="#eaeaea"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

        </android.support.v4.widget.SwipeRefreshLayout>

</LinearLayout>

2)实现:

public class WidgetActivity extends Activity implements SwipeRefreshLayout.OnRefreshListener, MenuItem.OnMenuItemClickListener {

    public static final int NONE = 0;
    public static final int LIST_V = 1;
    public static final int LIST_H = 2;
    public static final int GRID_V = 3;
    public static final int GRID_H = 4;
    public static final int STAGGERED_GRID_V = 5;
    public static final int STAGGERED_GRID_H = 6;

    int mOrientation;
    RecyclerView recyclerView;
    SwipeRefreshLayout refreshLayout;
    Toolbar toolbar;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mOrientation = getIntent().getIntExtra("orientation", NONE);
        setContentView(R.layout.widget_layout);
        recyclerView = (RecyclerView) findViewById(R.id.recycler);
        refreshLayout = (SwipeRefreshLayout) findViewById(R.id.refresh);
        refreshLayout.setOnRefreshListener(this);
        refreshLayout.setColorSchemeResources(android.R.color.holo_blue_bright,
                android.R.color.holo_green_light,
                android.R.color.holo_orange_light,
                android.R.color.holo_red_light);
        refreshLayout.setProgressBackgroundColor(R.color.refresh_bg);

        toolbar = (Toolbar) findViewById(R.id.toolbar);
        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.user);
        Bitmap b =createRoundConerImage(bitmap);
        toolbar.setNavigationIcon(new BitmapDrawable(b));
        //toolbar.setLogo(R.drawable.ic_launcher);
        setActionBar(toolbar);

        switch (mOrientation) {
            case LIST_V:
                initListView(true);
                break;
            case LIST_H:
                initListView(false);
                break;
            case GRID_V:
                initGridView(true);
                break;
            case GRID_H:
                initGridView(false);
                break;
            case STAGGERED_GRID_V:
                initStaggeredGridView(true);
                break;
            case STAGGERED_GRID_H:
                initStaggeredGridView(false);
                break;
        }
    }


    private View initListView(boolean isVer) {
        toolbar.setSubtitle(isVer ?"LinearLayoutManager Vertical":"LinearLayoutManager Horizontal");

        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        layoutManager.setOrientation(isVer ? LinearLayoutManager.VERTICAL : LinearLayoutManager.HORIZONTAL);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(new ListAdapter(this,isVer));

       // recyclerView.setHasFixedSize(true);
        recyclerView.setBackgroundColor(Color.WHITE);
        return recyclerView;
    }

    private View initGridView(boolean isVer) {
        toolbar.setSubtitle(isVer ?"GridLayoutManager Vertical":"GridLayoutManager Horizontal");
        GridLayoutManager layoutManager = new GridLayoutManager(this,isVer ?3:4);
        layoutManager.setOrientation(isVer ? LinearLayoutManager.VERTICAL : LinearLayoutManager.HORIZONTAL);
        recyclerView.setLayoutManager(layoutManager);

        recyclerView.setHasFixedSize(true);
        recyclerView.setAdapter(new GridAdapter(this,isVer));
        return recyclerView;
    }

    private View initStaggeredGridView(boolean isVer) {
        toolbar.setSubtitle(isVer ?"StaggeredGridLayoutManager Vertical":"StaggeredGridLayoutManager Horizontal");
        StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(2,isVer ? LinearLayoutManager.VERTICAL : LinearLayoutManager.HORIZONTAL);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(new StaggeredGridAdapter(this,isVer));
        return recyclerView;
    }

    @Override
    public void onRefresh() {
        refreshLayout.postDelayed(new Runnable() {
            @Override
            public void run() {
                refreshLayout.setRefreshing(false);
            }
        },3000);
    }

    private String[] menuTitles;
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        if (menuTitles == null) {
            menuTitles = getResources().getStringArray(R.array.style_names);
        }

        for (String name : menuTitles){
            MenuItem menuItem = menu.add(name);
            menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
            menuItem.setOnMenuItemClickListener(this);
        }

        return true;
    }

    @Override
    public boolean onMenuItemClick(MenuItem item) {
        for (int i = 0; i < menuTitles.length; i++) {

            if (item.getTitle().equals(menuTitles[i])) {
                Toast.makeText(this, item.getTitle(), Toast.LENGTH_SHORT).show();
                return true;
            }
        }
        return false;
    }
    private Bitmap createRoundConerImage(Bitmap source) {
        final Paint paint = new Paint();
        paint.setAntiAlias(true);

        int size = Math.min(source.getWidth(),source.getHeight());

        Bitmap target = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(target);
        RectF rect = new RectF(0, 0, size, size);
        canvas.drawRoundRect(rect, size /2, size/2, paint);
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
        canvas.drawBitmap(source, 0, 0, paint);
        return target;
    }

}

12、CardView有立体阴影的控件

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.CardView
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="5dp"
        card_view:cardBackgroundColor="@color/cardview_light_background"
        card_view:cardCornerRadius="1dp" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="5dp" >

            <ImageView
                android:id="@+id/pic"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:scaleType="centerCrop" />

            <TextView
                android:id="@+id/name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/pic"
                android:layout_centerHorizontal="true"
                android:gravity="center"
                android:textColor="#212121"
                android:textSize="16sp" />
        </RelativeLayout>

    </android.support.v7.widget.CardView>

</RelativeLayout>

—————————————————————————————————————————————————–

JAVA(SSM、SSH等)20项目视频教程,共134G

下载地址:

https://item.taobao.com/item.htm?id=558680925808

———————-课程目录——————————

第01项目:OA办公自动化项目(四套)
第02项目:CRM客户关系管理项目(两套)
第03项目:宅急送项目
第04项目:杰信商贸SSH版
第05项目:电力项目(两套)
第06项目:校内网项目
第07项目:Java邮件开发教程
第08项目:java网上在线支付实战视频
第09项目:俄罗斯方块游戏开发_视频教程
第10项目:交通灯管理系统视频教程
第11项目:银行业务调度系统视频教程
第12项目:供应链系统视频教程
第13项目:网上商城项目
第14项目:药品集中采购系统视频教程
第15项目:杰信商贸SSM版
第16项目:国家税务协同平台项目
第17项目:javaWeb聊天室
第18项目:点餐系统
第19项目:网上书店
第20项目:手机进销存系统
—————————————————————————————————————————————————–

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lovoo

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值