倒计时

依赖:

 implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    compile 'com.facebook.fresco:fresco:1.5.0'


package hc.com.day12rikao;



import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;


import java.util.ArrayList;
import java.util.List;


public class MainActivity extends AppCompatActivity  {


    private ViewPager mImgViewPager;
    private List<Integer> list ;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }


    private void initView() {
        mImgViewPager = (ViewPager) findViewById(R.id.img_viewPager);
        //得到图片
      list =  new ArrayList<>();
        list.add(R.mipmap.ic_launcher);
        list.add(R.mipmap.ic_launcher);
        list.add(R.mipmap.ic_launcher);
        MyAdapter myAdapter = new MyAdapter(MainActivity.this, list);
        mImgViewPager.setAdapter(myAdapter);
    }

}


MyAdapter

package hc.com.day12rikao;


import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;




import java.util.List;


/**
 * Created by kang on 2018/1/9.
 */


public class MyAdapter extends PagerAdapter {
    private Context context;
    private List<Integer> lsit;




    public MyAdapter(Context context, List<Integer> lsit) {
        this.context = context;
        this.lsit = lsit;
    }


    @Override
    public int getCount() {
        return lsit.size();
    }


    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }


    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        ImageView imageView = new ImageView(context);
        imageView.setImageResource(lsit.get(position));
        container.addView(imageView);
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        return imageView;
    }


    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }
}


package hc.com.day12rikao;


import android.app.Application;

APP
import com.facebook.drawee.backends.pipeline.Fresco;


/**
 * Created by kang on 2018/1/9.
 */


public class MyApp extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        Fresco.initialize(this);
    }
}

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="hc.com.day12rikao.MainActivity">


        <android.support.v4.view.ViewPager
    android:id="@+id/img_viewPager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>


</RelativeLayout>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值