今日头条

Mainxml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/dl"

    >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        >
      <RelativeLayout
          android:layout_width="wrap_content"
          android:layout_height="wrap_content">
          <ImageView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:src="@mipmap/ic_launcher"
              />
          <TextView
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:text="今日头条"
              android:textSize="28sp"
              android:gravity="center"
              />
      </RelativeLayout>
        <android.support.v4.view.ViewPager
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/vp"
            >
            <android.support.design.widget.TabLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/tab_layout"
                ></android.support.design.widget.TabLayout>
        </android.support.v4.view.ViewPager>

    </LinearLayout>
    <LinearLayout
        android:layout_width="300dp"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:layout_gravity="start"
        android:background="#ff0"
        >
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="用户名"
            />
    </LinearLayout>
</android.support.v4.widget.DrawerLayout>

 

fragment1:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:orientation="vertical"
    tools:context=".fragment.fragment1">

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

</LinearLayout>

 

fragment2:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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=".fragment.fragment2">

    <!-- TODO: Update blank fragment layout -->
    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="@string/hello_blank_fragment" />

</FrameLayout>

 

item_layout

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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=".fragment.fragment2">

    <!-- TODO: Update blank fragment layout -->
    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="@string/hello_blank_fragment" />

</FrameLayout>

 

mainactivity:

package com.example.zklx4;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

import com.example.zklx4.fragment.fragment1;
import com.example.zklx4.fragment.fragment2;
import com.example.zklx4.myadapter.Fragmentadapter;

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

public class MainActivity extends AppCompatActivity {

    private TabLayout tab_layout;
    private ViewPager vp;
    private List<Fragment> fragments;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //初始化控件
        tab_layout = findViewById(R.id.tab_layout);
        vp = findViewById(R.id.vp);
        //创建一个集合
        fragments = new ArrayList<>();
        fragments.add(new fragment1());
        fragments.add(new fragment2());
        fragments.add(new fragment2());
        fragments.add(new fragment2());
        fragments.add(new fragment2());
        //创建一个适配器
       vp.setAdapter(new Fragmentadapter(getSupportFragmentManager(),fragments));

    }
}

fragment1:

package com.example.zklx4.fragment;


import android.annotation.SuppressLint;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.widget.ImageView;

import com.example.zklx4.R;
import com.example.zklx4.bean.user;
import com.example.zklx4.myadapter.padapter;
import com.example.zklx4.myadapter.vadapter;
import com.google.gson.Gson;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.ByteBuffer;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class fragment1 extends Fragment {


    private ViewPager vp;
    @SuppressLint("HandlerLeak")
    /*private Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (msg.what==0){
               String s = (String) msg.obj;
                Gson gson = new Gson();
                user fromJson = gson.fromJson(s, user.class);
                List<user.ResultsBean> results = fromJson.getResults();
                Log.i("bbb",results+"");
                //Log.i("aaa",results.get(0).getWho());
                //vp.setAdapter(new padapter(getActivity(),results));
                handler.sendEmptyMessageDelayed(1,2000);
            } else if (msg.what==1) {
                int currentItem = vp.getCurrentItem();
                vp.setCurrentItem(currentItem+1);
                handler.sendEmptyMessageDelayed(1,2000);

            }
        }
    };*/
    public fragment1() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_fragment1, container, false);
        vp = view.findViewById(R.id.vp);

        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        new Thread(){
            @Override
            public void run() {
                super.run();
                String path="http://result.eolinker.com/iYXEPGn4e9c6dafce6e5cdd23287d2bb136ee7e9194d3e9?uri=banner";
                try {
                    URL url = new URL(path);
                    HttpURLConnection coon = (HttpURLConnection) url.openConnection();
                    coon.setConnectTimeout(5000);
                    coon.setRequestMethod("GET");
                    if (coon.getResponseCode()==200){
                        InputStream inputStream = coon.getInputStream();
                        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                        int len =-1;
                        byte[] bytes = new byte[1024];
                        while((len=inputStream.read(bytes))!=-1){
                            byteArrayOutputStream.write(bytes,0,len);
                        }
                        String s2 = byteArrayOutputStream.toString();
                        String s = new String(s2);
                        Log.i("aaa",s);
                        /*Message message = new Message();
                        message.what=0;
                        message.obj=s;


                        handler.sendMessage(message);*/
                        Gson gson=new Gson();
                        user s1 = gson.fromJson("s", user.class);
                        List<user.ResultsBean> results = s1.getResults();
                        vp.setAdapter(new padapter(getActivity(),results));
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }.start();
    }
}

fragment2:

package com.example.zklx4.fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.zklx4.R;

/**
 * A simple {@link Fragment} subclass.
 */
public class fragment2 extends Fragment {


    public fragment2() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_fragment2, container, false);
        return view;
    }

}

app:

package com.example.zklx4.app;

import android.app.Application;
import android.content.Context;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;

public class App extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        ImageLoaderConfiguration build = new ImageLoaderConfiguration.Builder(getApplicationContext()).build();
        ImageLoader.getInstance().init(build);
    }
}

 

fragmentAdapter:

package com.example.zklx4.myadapter;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.ViewGroup;

import java.util.List;

public class Fragmentadapter extends FragmentPagerAdapter {
    private List<Fragment> fragments;
    private String title[]={"推荐","社会","咨询","热点","头条"};

    public Fragmentadapter(FragmentManager fm, List<Fragment> fragments) {
        super(fm);
        this.fragments = fragments;
    }

    @Override
    public Fragment getItem(int position) {
        return fragments.get(position);
    }

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

    @Override
    public CharSequence getPageTitle(int position) {
        return title[position];
    }
}

 

padapter:

package com.example.zklx4.myadapter;

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

import com.example.zklx4.bean.user;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

public class padapter extends PagerAdapter {
    private Context context;
    private List<user.ResultsBean> results;

    public padapter(Context context, List<user.ResultsBean> results) {
        this.context = context;
        this.results = results;
    }

    @Override
    public int getCount() {
        return Integer.MAX_VALUE;
    }

    @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.setScaleType(ImageView.ScaleType.FIT_XY);
        Log.i("aaaa","11111");
        Log.i("aaa",results.get(1).getWho());
        try{
            ImageLoader.getInstance().displayImage(results.get(position % results.size()).getImages().get(0), imageView);
        }catch (Exception e){
            e.getMessage();
        }

        Log.i("aaa",imageView+"");
        container.addView(imageView);
        return imageView;


    }

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

vadapter:

package com.example.zklx4.myadapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.example.zklx4.R;
import com.example.zklx4.bean.user;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

public class vadapter extends BaseAdapter {
    private Context context;
    private List<user.ResultsBean> results;
    public vadapter(Context context, List<user.ResultsBean> results) {
        this.context = context;
        this.results = results;
    }

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

    @Override
    public Object getItem(int i) {
        return results.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        holder holder = null;
        if (view==null){
            holder = new holder();
            view=View.inflate(context, R.layout.item_layout,null);
            holder.imag_view=view.findViewById(R.id.imag_view);
            view.setTag(holder);
        }else{
            holder= (vadapter.holder) view.getTag();
        }
        ImageLoader.getInstance().displayImage(results.get(i).getImages().get(0),holder.imag_view);
        return view;
    }
    class holder{
        ImageView imag_view;
    }
}
Python网络爬虫与推荐算法新闻推荐平台:网络爬虫:通过Python实现新浪新闻的爬取,可爬取新闻页面上的标题、文本、图片、视频链接(保留排版) 推荐算法:权重衰减+标签推荐+区域推荐+热点推荐.zip项目工程资源经过严格测试可直接运行成功且功能正常的情况才上传,可轻松复刻,拿到资料包后可轻松复现出一样的项目,本人系统开发经验充足(全领域),有任何使用问题欢迎随时与我联系,我会及时为您解惑,提供帮助。 【资源内容】:包含完整源码+工程文件+说明(如有)等。答辩评审平均分达到96分,放心下载使用!可轻松复现,设计报告也可借鉴此项目,该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的。 【提供帮助】:有任何使用问题欢迎随时与我联系,我会及时解答解惑,提供帮助 【附带帮助】:若还需要相关开发工具、学习资料等,我会提供帮助,提供资料,鼓励学习进步 【项目价值】:可用在相关项目设计中,皆可应用在项目、毕业设计、课程设计、期末/期中/大作业、工程实训、大创等学科竞赛比赛、初期项目立项、学习/练手等方面,可借鉴此优质项目实现复刻,设计报告也可借鉴此项目,也可基于此项目来扩展开发出更多功能 下载后请首先打开README文件(如有),项目工程可直接复现复刻,如果基础还行,也可在此程序基础上进行修改,以实现其它功能。供开源学习/技术交流/学习参考,勿用于商业用途。质量优质,放心下载使用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值