Android_校易app开发日志_5

今天状态好差,困得一批。昨晚睡得太晚了。。。

今日学习进度

昨天晚上开着as做了好久ps,可能是ps占的内存太大了,as丢了俩文件夹,今天上午花了几个小时发现还原不了了,下午又重新写了一遍

以后一定要随手备份。。。然后晚上也没写多少东西,商品详细信息界面写了个viewpager用来浏览商品图片。

 

package com.example.xiaoyi_test_2;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.xiaoyi_test_2.Utils.PageTransFormer;

public class ShowDetailActivity extends AppCompatActivity implements View.OnClickListener, ViewPager.OnPageChangeListener {
    private ImageView Iv;
    private TextView tv_img;
    private ImageView iv_return;
    private ViewPager imgviewpager;
    //定义图片的资源数组
    private int[] ResId = new int[]{
            R.drawable.plus_fang,
            R.drawable.flydream,
            R.drawable.pluss_green
    };
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_show_detail);
        Log.d("-------------","1");
        initViews();
    }

    private void initViews() {
        Log.d("-------------","2");
        //得到当前页面的viewpager控件,并为他设置adapter
        imgviewpager=findViewById(R.id.shoudetail_viewpag);

        imgviewpager.setAdapter(new PagerAdapter() {
            @Override
            public int getCount() {
                return ResId.length;
            }

            @NonNull
            @Override
            public Object instantiateItem(@NonNull ViewGroup container, int position) {
                ImageView view = new ImageView(ShowDetailActivity.this);
                view.setImageResource(ResId[position]);
                container.addView(view);
                return view;
            }
            @Override
            public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
                container.removeView((View) object);
            }
            @Override
            public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
                return view==object;
            }
        });
        Log.d("-------------","3");
        imgviewpager.addOnPageChangeListener(this);
        imgviewpager.setPageMargin(10);
        imgviewpager.setOffscreenPageLimit(3);
        imgviewpager.setPageTransformer(false,new PageTransFormer());
        tv_img=findViewById(R.id.tv_img);
        iv_return=findViewById(R.id.shoudetail_iv_return);
        iv_return.setOnClickListener(this);
        Log.d("-------------","4");

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.shoudetail_iv_return:{
                Intent intent=new Intent(ShowDetailActivity.this,MainActivity.class);
                setResult(0,intent);
                finish();
                break;
            }
        }
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {

    }

    @Override
    public void onPageScrollStateChanged(int state) {
        if (state==2){
            tv_img.setText(""+(imgviewpager.getCurrentItem()+1)+"/"+ResId.length);
        }
    }
}

 

 明日计划

明天下午应该没课,打算把详细信息界面写完,晚上把爬虫那个项目完善一下写个博客。

 

posted @ 2020-03-11 20:41  XiaoGao128  阅读(184)  评论(0编辑  收藏  举报