最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android實(shí)現(xiàn)九宮格橫向左右滑動(dòng)

 更新時(shí)間:2018年08月17日 09:34:07   作者:zuo_er_lyf  
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)九宮格橫向左右滑動(dòng),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

項(xiàng)目中大多都會(huì)有很多的分類,且左右滑動(dòng),如美團(tuán)首頁(yè)(下圖):

不難發(fā)現(xiàn)包含2部分內(nèi)容:1.左右滑動(dòng)的頁(yè)面,2.指示器。

大度一般都會(huì)想到,viewPager+GridView,這里介紹另外的的一種方法,也做下記錄;

GridViewPager+MagicIndicator(萬(wàn)能指示器)

一、引入build.gradle

compile 'com.yhy:gvp:1.1.0'  
compile 'com.github.hackware1993:MagicIndicator:1.5.0'

如果報(bào)錯(cuò),在項(xiàng)目build.gradle中加入:

repositories {
  ...
  maven {
    url "https://jitpack.io"
  }
}

二、布局代碼

<LinearLayout
   android:gravity="center_horizontal"
   android:layout_gravity="center_horizontal"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:orientation="vertical">
 
 
   <com.yhy.gvp.widget.GridViewPager
    android:paddingLeft="15dp"
    android:paddingRight="15dp"
    android:id="@+id/grid_viewpager"
    android:layout_width="match_parent"
    android:layout_height="150dp"
    app:num_columns="5"
    app:page_size="10"></com.yhy.gvp.widget.GridViewPager>
 
   <net.lucode.hackware.magicindicator.MagicIndicator
    android:id="@+id/indicator_container"
    android:layout_width="wrap_content"
    android:layout_height="30dp">  
   </net.lucode.hackware.magicindicator.MagicIndicator>
</LinearLayout>

屬性說(shuō)明:

三、關(guān)鍵代碼:

@InjectView(R.id.grid_viewpager)
  GridViewPager gridViewpager;
  @InjectView(R.id.indicator_container)
  MagicIndicator indicatorContainer; 使用ButterKnife這里不多介紹
 
indexTypeAdapter=new IndexTypeAdapter(getActivity(),R.layout.item_index_type,typeDatas);//頁(yè)面內(nèi)容適配器
    gridViewpager.setGVPAdapter(indexTypeAdapter);
 
    Log.i("datas",(int) Math.ceil(typeDatas.size() / 10)+"");
    CommonNavigator commonNavigator = new CommonNavigator(context);//指示器
    commonNavigator.setAdapter(new CommonNavigatorAdapter() {
      @Override
      public int getCount() {
        int num=typeDatas.size()/10;
        if(typeDatas.size() % 10>0){
          num++;
        }
        return typeDatas==null?0:num;
      }
 
      @Override
      public IPagerTitleView getTitleView(Context mContext, final int i) {
        CommonPagerTitleView commonPagerTitleView = new CommonPagerTitleView(context);
        View view=View.inflate(context,R.layout.single_image_layout,null);
        final ImageView iv_image=view.findViewById(R.id.iv_image);
        iv_image.setImageResource(R.drawable.point_unfocused);
 
        commonPagerTitleView.setContentView(view);//指示器引入外部布局,可知指示器內(nèi)容可根據(jù)需求設(shè)置,多樣化
        commonPagerTitleView.setOnPagerTitleChangeListener(new CommonPagerTitleView.OnPagerTitleChangeListener() {
          @Override
          public void onSelected(int i, int i1) {
            iv_image.setImageResource(R.drawable.point_focused);
          }
 
          @Override
          public void onDeselected(int i, int i1) {
            iv_image.setImageResource(R.drawable.point_unfocused);
          }
 
          @Override
          public void onLeave(int i, int i1, float v, boolean b) {
 
          }
 
          @Override
          public void onEnter(int i, int i1, float v, boolean b) {
 
          }
        });
        return commonPagerTitleView;
      }
 
      @Override
      public IPagerIndicator getIndicator(Context context) {
        return null;
      }
    });
    indicatorContainer.setNavigator(commonNavigator);
    ViewPagerHelper.bind(indicatorContainer, gridViewpager);//頁(yè)面內(nèi)容與指示器關(guān)聯(lián)

四、左右滑動(dòng)頁(yè)面內(nèi)容適配器adapter

public class IndexTypeAdapter extends GVPAdapter<IndexAllTypeBean.TypeListBean> {
  private Context context;
  public IndexTypeAdapter(Context context,int layoutResId, @Nullable List<IndexAllTypeBean.TypeListBean> data) {
    super(layoutResId, data);
    this.context=context;
  }
 
  @Override
  public void bind(View item, int position, IndexAllTypeBean.TypeListBean data) {
    CircleImageView iv_image=item.findViewById(R.id.iv_image);
    TextView tv_type_name=item.findViewById(R.id.tv_type_name);
    Picasso.with(context).load(data.getImageUrl()).into(iv_image);
    
      tv_type_name.setText(data.getName());
    
  }
}
//IndexAllTypeBean.TypeListBean 為數(shù)據(jù)內(nèi)容實(shí)體類,不做介紹

五、內(nèi)容item布局

<LinearLayout
  android:orientation="vertical"
  android:paddingBottom="5dp"
  android:layout_marginLeft="5dp"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content">
//自定義圓形圖片,可用ImageView 替代
  <com.example.administrator.takeout.ui.widght.CircleImageView
   android:id="@+id/iv_image"
   android:gravity="center_horizontal"
   android:layout_gravity="center_horizontal"
   android:layout_width="40dp"
   android:layout_height="40dp" />
  <TextView
   android:layout_marginTop="5dp"
   android:gravity="center_horizontal"
   android:layout_gravity="center_horizontal"
   android:id="@+id/tv_type_name"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content" />
</LinearLayout>

 以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android寫一個(gè)實(shí)時(shí)輸入框功能

    Android寫一個(gè)實(shí)時(shí)輸入框功能

    這篇文章主要介紹了Android寫一個(gè)實(shí)時(shí)輸入框功能,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-04-04
  • Android使用百度語(yǔ)音識(shí)別的示例代碼

    Android使用百度語(yǔ)音識(shí)別的示例代碼

    本篇文章主要介紹了Android使用百度語(yǔ)音識(shí)別的示例代碼,詳細(xì)介紹了使用百度語(yǔ)音識(shí)別,完成語(yǔ)音識(shí)別的功能,有興趣的可以了解一下。
    2017-02-02
  • Android性能優(yōu)化方案詳情

    Android性能優(yōu)化方案詳情

    這篇文章主要給大家分享的是Android項(xiàng)目工程內(nèi)的一些性能優(yōu)化方式,文章圍繞Android項(xiàng)目工程優(yōu)化方式展開內(nèi)容,需要的朋友可以參考一下文章的具體詳情,希望對(duì)你有所幫助
    2021-11-11
  • Android開發(fā)常用標(biāo)簽小結(jié)

    Android開發(fā)常用標(biāo)簽小結(jié)

    這篇文章主要介紹了Android開發(fā)常用標(biāo)簽,分析總結(jié)了Android開發(fā)中常見標(biāo)簽的使用技巧,需要的朋友可以參考下
    2015-05-05
  • Android中自定義對(duì)話框(Dialog)的實(shí)例代碼

    Android中自定義對(duì)話框(Dialog)的實(shí)例代碼

    這篇文章介紹了Android中自定義對(duì)話框(Dialog)的實(shí)例代碼,有需要的朋友可以參考一下
    2013-08-08
  • 實(shí)戰(zhàn)android打包和簽名

    實(shí)戰(zhàn)android打包和簽名

    本篇文章給大家通過(guò)實(shí)例講解了如何對(duì)android項(xiàng)目打包和簽名,并把用到的文件和流程做了注視,需要的朋友參考一下吧。
    2017-12-12
  • Android 網(wǎng)絡(luò)請(qǐng)求框架解析之okhttp與okio

    Android 網(wǎng)絡(luò)請(qǐng)求框架解析之okhttp與okio

    HTTP是現(xiàn)代應(yīng)用常用的一種交換數(shù)據(jù)和媒體的網(wǎng)絡(luò)方式,高效地使用HTTP能讓資源加載更快,節(jié)省帶寬,OkHttp是一個(gè)高效的HTTP客戶端,下面這篇文章主要給大家介紹了關(guān)于OkHttp如何用于安卓網(wǎng)絡(luò)請(qǐng)求,需要的朋友可以參考下
    2021-10-10
  • android新建草稿刪除后下次開機(jī)還會(huì)顯示保存的草稿

    android新建草稿刪除后下次開機(jī)還會(huì)顯示保存的草稿

    android 新建一個(gè)草稿,保存,然后全部刪除會(huì)話,關(guān)機(jī)再開機(jī)后還會(huì)顯示保存的草稿,下面與大家分享下具體的解決方法
    2013-06-06
  • SpringBoot實(shí)現(xiàn)短信驗(yàn)證碼登錄功能(案例)

    SpringBoot實(shí)現(xiàn)短信驗(yàn)證碼登錄功能(案例)

    這篇文章主要介紹了SpringBoot實(shí)現(xiàn)短信驗(yàn)證碼登錄功能,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧
    2024-08-08
  • AndroidStudio Gradle基于友盟的多渠道打包方法

    AndroidStudio Gradle基于友盟的多渠道打包方法

    這篇文章主要介紹了AndroidStudio Gradle基于友盟的多渠道打包方法,需要的朋友可以參考下
    2017-09-09

最新評(píng)論

湟中县| 元谋县| 遵化市| 长武县| 贵溪市| 砚山县| 英山县| 喀喇沁旗| 惠东县| 岱山县| 龙州县| 常山县| 潢川县| 灵武市| 云龙县| 都匀市| 武功县| 元阳县| 康定县| 昌宁县| 桐梓县| 上思县| 黄大仙区| 永胜县| 枝江市| 建水县| 什邡市| 即墨市| 扬中市| 衡水市| 辉南县| 新营市| 桂平市| 南通市| 西城区| 甘肃省| 吐鲁番市| 喀喇| 昭通市| 贵溪市| 务川|