activity_main <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.bwei.jingdongdemo.MainActivity"> <com.hjm.bottomtabbar.BottomTabBar android:id="@+id/Btbar" android:layout_width="match_parent" android:layout_height="match_parent"> </com.hjm.bottomtabbar.BottomTabBar> </android.support.constraint.ConstraintLayout> fragment1<?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"> <com.youth.banner.Banner android:id="@+id/bn" android:layout_width="match_parent" android:layout_height="300px"></com.youth.banner.Banner> </LinearLayout> fragment2<?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"> <TextView android:id="@+id/fragment2" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="第二个页面" /> </LinearLayout> 3.4.5. MainActivityimport android.graphics.Color; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import com.hjm.bottomtabbar.BottomTabBar; public class MainActivity extends AppCompatActivity { private BottomTabBar btbar; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btbar = (BottomTabBar) findViewById(R.id.Btbar); btbar.init(getSupportFragmentManager()) .setImgSize(60,60) .setFontSize(10) .setTabPadding(4,6,10) .setChangeColor(Color.RED,Color.BLACK) .addTabItem("首页",R.mipmap.shouye,shouye.class) .addTabItem("分类",R.mipmap.icon_homepage,FenLei.class) .addTabItem("发现",R.mipmap.icon_findall,FaXian.class) .addTabItem("购物车",R.mipmap.icon_shoppingcart,GouWuChe.class) .addTabItem("我的",R.mipmap.icon_mine,My.class) .isShowDivider(false) .setOnTabChangeListener(new BottomTabBar.OnTabChangeListener(){ @Override public void onTabChange(int position, String name) { } }); } } Myimport android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; /** * Created by HQ on 2017/11/4. */ public class My extends Fragment { private View view; @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { view = inflater.inflate(R.layout.fragment5, container, false); return view; } } shouyeimport android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import com.youth.banner.Banner; import com.youth.banner.loader.ImageLoaderInterface; import java.util.ArrayList; /** * Created by HQ on 2017/11/4. */ public class shouye extends Fragment { private View view; private ArrayList<String> list = new ArrayList<String>(); private Banner ban; @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { view = inflater.inflate(R.layout.fragment1, container, false); ban = (Banner) view.findViewById(R.id.bn); list.add("http://pic8.nipic.com/20100701/5290458_114840036316_2.jpg"); list.add("http://pic2.nipic.com/20090424/1468853_230119053_2.jpg"); list.add("http://img3.3lian.com/2013/s1/20/d/57.jpg"); list.add("http://pic39.nipic.com/20140226/18071023_164300608000_2.jpg"); list.add("http://a0.att.hudong.com/15/08/300218769736132194086202411_950.jpg"); ban.setImageLoader( new ImgApp());//引用ImgApp,加载里面的东西 ban.setImages(list); ban.isAutoPlay(true); ban.setDelayTime(2000); ban.start(); return view; } } Faxianimport android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; /** * Created by HQ on 2017/11/4. */ public class FaXian extends Fragment { private View view; @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { view = inflater.inflate(R.layout.fragment3, container, false); return view; } } FenLeiimport android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; /** * Created by HQ on 2017/11/4. */ public class FenLei extends Fragment { private View view; @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { view = inflater.inflate(R.layout.fragment2, container, false); return view; } } GouWuCheimport android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; /** * Created by HQ on 2017/11/4. */ public class GouWuChe extends Fragment { private View view; @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { view = inflater.inflate(R.layout.fragment4, container, false); return view; } }
ImgAppimport android.content.Context; import android.widget.ImageView; import com.youth.banner.loader.ImageLoader; /** * Created by HQ on 2017/11/4. */ public class ImgApp extends ImageLoader { public void displayImage(Context context, Object path, ImageView imageView) { com.nostra13.universalimageloader.core.ImageLoader.getInstance().displayImage((String) path,imageView); } }
ImgApp2import android.app.Application; import com.nostra13.universalimageloader.core.ImageLoader; import com.nostra13.universalimageloader.core.ImageLoaderConfiguration; /** * Created by HQ on 2017/11/4. */ public class ImgApp2 extends Application { @Override public void onCreate() { super.onCreate(); ImageLoaderConfiguration build = new ImageLoaderConfiguration.Builder(this).build(); ImageLoader.getInstance().init(build); } } //权限<uses-permission android:name="android.permission.INTERNET"></uses-permission> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>android:name=".ImgApp2"
//依赖compile 'com.android.support:appcompat-v7:26.+' compile 'com.android.support.constraint:constraint-layout:1.0.2' compile 'com.youth.banner:banner:1.4.9' compile 'com.hjm:BottomTabBar:1.1.1' testCompile 'junit:junit:4.12' compile files('libs/universal-image-loader-1.9.5.jar') //导imageLoader的java包
京东fragment和无限轮播
最新推荐文章于 2023-03-10 17:29:28 发布