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

android使用 ScrollerView 實(shí)現(xiàn) 可上下滾動的分類欄實(shí)例

 更新時間:2017年01月17日 16:48:26   作者:李詩雨  
本篇文章主要介紹了android使用 ScrollerView 實(shí)現(xiàn) 可上下滾動的分類欄實(shí)例,具有一定的參考價值,有興趣的可以了解一下。

如果不考慮更深層的性能問題,我個人認(rèn)為ScrollerView還是很好用的。而且單用ScrollerView就可以實(shí)現(xiàn)分類型的RecyclerView或ListView所能實(shí)現(xiàn)的效果。

下面我單單從效果展示方面考慮,使用ScrollerView實(shí)現(xiàn)如下圖所示的可滾動的多條目分類,只是為了跟大家一起分享一下新思路。(平時:若從復(fù)用性等方面考慮,這顯然是存在瑕疵的~)

特點(diǎn)描述:

1.可上下滾動

2.有類似于網(wǎng)格布局的樣式

3.子條目具有點(diǎn)擊事件

剛看到這個效果時,首先想到的是使用分類型的RecyclerView 或者 ListView  ,里面再嵌套GridView來實(shí)現(xiàn)。

但轉(zhuǎn)而又一想ScrollerView也可以滾動,只要往里面循環(huán)添加子item不就可以了嗎。

實(shí)現(xiàn)的邏輯大致如下:


具體的實(shí)現(xiàn)如下:

第一步:布局里寫一個ScrollerView,里面添加一個豎直的線性布局

第二步:實(shí)例化垂直線性布局

allhonor_hscroll = (LinearLayout) findViewById(R.id.allhonor_hscroll); 

第三步:聯(lián)網(wǎng)請求獲取數(shù)據(jù)

setAllHonorData(); 
/** 
  * 使用okhttp 
  */ 
  public void setAllHonorData() { 
    OkHttpUtils 
        .get() 
        .url(url) 
        .build() 
        .execute(new StringCallback() { 
          @Override 
          public void onError(okhttp3.Call call, Exception e, int id) { 
            Log.e("TAG", "111"); 
            Log.e("TAG", "onError" + e.getMessage()); 
          } 
 
          @Override 
          public void onResponse(String response, int id) { 
            Log.e("TAG", "222"); 
            Log.e("TAG", "onRespons" + response); 
 
            //聯(lián)網(wǎng)成功后使用fastjson來解析數(shù)據(jù) 
            processData(response); 
          } 
 
          @Override 
          public void onBefore(Request request, int id) { 
          } 
 
          @Override 
          public void onAfter(int id) { 
          } 
 
        }); 
  } 
/** 
   * 使用fastjson進(jìn)行解析 
   * 
   * @param json 
   */ 
  private void processData(String json) { 
    //使用GsonFormat生成對應(yīng)的bean類 
    com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(json); 
    String data = jsonObject.getString("data"); 
    List<AllHonorBean.HornorBean> hornorsList = JSON.parseArray(data, AllHonorBean.HornorBean.class); 
 
    //測試是否解析數(shù)據(jù)成功 
//    String strTest = hornorsList.get(0).getRegion(); 
//    Log.e("TAG", strTest); 
 
    //第四步:裝配數(shù)據(jù),使用兩層for循環(huán) 
 
  } 

第四步:設(shè)置兩種item的布局

第一種item布局:item_allhornors0.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
  android:layout_width="match_parent" 
  android:layout_height="match_parent" 
  android:background="#ffffff" 
  android:orientation="vertical"> 
 
  <TextView 
    android:id="@+id/tv_allhornors_big" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="#11000000" 
    android:gravity="center_vertical" 
    android:paddingBottom="12dp" 
    android:paddingLeft="13dp" 
    android:paddingTop="12dp" 
    android:text="熱門" 
    android:textColor="#000000" 
    android:textSize="14sp" /> 
 
  <View 
    android:layout_width="match_parent" 
    android:layout_height="1dp" 
    android:background="#11000000" /> 
 
</LinearLayout> 

第二種item布局:item_allhornors1.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
  android:layout_width="match_parent" 
  android:layout_height="wrap_content" 
  android:background="#ffffff" 
  android:orientation="vertical"> 
 
  <LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 
 
    <TextView 
      android:id="@+id/tv_allhornors_sn0" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:clickable="true" 
      android:gravity="center" 
      android:paddingBottom="12sp" 
      android:paddingTop="12sp" 
      android:text="你好你好" 
      android:textColor="#000000" 
      android:textSize="13sp" /> 
 
    <View 
      android:layout_width="1dp" 
      android:layout_height="match_parent" 
      android:background="#11000000" /> 
 
    <!--注意這里的text文本一定要為空,不要設(shè)置任何內(nèi)容--> 
    <TextView 
      android:id="@+id/tv_allhornors_sn1" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:clickable="true" 
      android:gravity="center" 
      android:paddingBottom="12sp" 
      android:paddingTop="12sp" 
      android:text="" 
      android:textColor="#000000" 
      android:textSize="13sp" /> 
  </LinearLayout> 
 
  <View 
    android:layout_width="match_parent" 
    android:layout_height="1dp" 
    android:background="#11000000" /> 
 
</LinearLayout> 

第五步:裝配數(shù)據(jù)

if (hornorsList != null && hornorsList.size() > 0) { 
      //-->外層 
      for (int i = 0; i < hornorsList.size(); i++) { 
        //創(chuàng)建并添加第一種item布局 
        View globalView = View.inflate(this, R.layout.item_allhornors0, null); 
        TextView tv_allhornors_big = (TextView) globalView.findViewById(R.id.tv_allhornors_big); 
        AllHonorBean.HornorBean hornorsListBean = hornorsList.get(i); 
        String region = hornorsListBean.getRegion(); 
        //外層for中直接裝配數(shù)據(jù) 
        tv_allhornors_big.setText(region); 
        //將布局添加進(jìn)去 
        allhonor_hscroll.addView(globalView); 
 
        List<AllHonorBean.HornorBean.FestivalsBean> festivalsList = hornorsListBean.getFestivals(); 
        //-->內(nèi)層,每次裝兩個數(shù)據(jù) 
        for (int j = 0; j < festivalsList.size(); j = j + 2) { 
          //創(chuàng)建并添加第二種item布局 
          View smallView = View.inflate(this, R.layout.item_allhornors1, null); 
          final TextView tv_sn0 = (TextView) smallView.findViewById(R.id.tv_allhornors_sn0); 
          TextView tv_sn1 = (TextView) smallView.findViewById(R.id.tv_allhornors_sn1); 
 
          //順帶在這里就直接添加點(diǎn)擊事件的監(jiān)聽 
          if (j < festivalsList.size() - 1) { 
            setListener(tv_sn0, tv_sn1); 
          } 
 
          //裝配左邊的數(shù)據(jù) 
          honorName0 = festivalsList.get(j).getFestivalName(); 
          tv_sn0.setText(honorName0); 
 
          //判讀越界否 
          if (j < festivalsList.size() - 1) { 
            //裝配右邊的數(shù)據(jù) 
            honorName1 = festivalsList.get(j + 1).getFestivalName(); 
            tv_sn1.setText(honorName1); 
          } 
 
          //添加進(jìn)去 
          allhonor_hscroll.addView(smallView); 
        } 
      } 
    } 

點(diǎn)擊事件的監(jiān)聽:

private void setListener(final TextView tv_sn0, final TextView tv_sn1) { 
    //給左邊的TextView 設(shè)置監(jiān)聽 
    tv_sn0.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
        Toast.makeText(MainActivity.this, "" + tv_sn0.getText(), Toast.LENGTH_SHORT).show(); 
      } 
    }); 
 
    //給右邊的TextView 設(shè)置監(jiān)聽 
    tv_sn1.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
        Toast.makeText(MainActivity.this, "" + tv_sn1.getText(), Toast.LENGTH_SHORT).show(); 
      } 
    }); 
  } 

完成~

再看一眼最后效果:

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

相關(guān)文章

  • Android自定義照相機(jī)詳解

    Android自定義照相機(jī)詳解

    幾乎每個APP都會用的相機(jī)功能,下面小編把內(nèi)容整理分享到腳本之家平臺,供大家參考
    2016-04-04
  • Android使用VideoView出現(xiàn)無法播放此視頻問題的解決方法

    Android使用VideoView出現(xiàn)無法播放此視頻問題的解決方法

    Android提供了 VideoView組件,它的作用與ImageView類似,只是ImageView用于顯示圖片,而VideoView用于播放視頻,下面這篇文章主要給大家介紹了關(guān)于利用VideoView出現(xiàn)無法播放此視頻問題的解決方法,需要的朋友可以參考下
    2018-07-07
  • Jetpack?Compose實(shí)現(xiàn)點(diǎn)擊事件click的多種方法

    Jetpack?Compose實(shí)現(xiàn)點(diǎn)擊事件click的多種方法

    這篇文章主要介紹了Jetpack?Compose實(shí)現(xiàn)點(diǎn)擊事件的多種方法,Jetpack?Compose是一款基于Kotlin的聲明式UI工具包,可以方便地創(chuàng)建漂亮的用戶界面,下面我們就來看看Jetpack?Compose添加點(diǎn)擊事件都可以怎么實(shí)現(xiàn)
    2024-02-02
  • 淺談React Native打包apk的坑

    淺談React Native打包apk的坑

    下面小編就為大家?guī)硪黄獪\談React Native打包apk的坑。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-11-11
  • Android界面一鍵變灰開發(fā)深色適配模式編程示例

    Android界面一鍵變灰開發(fā)深色適配模式編程示例

    這篇文章主要為大家介紹了Android界面一鍵變灰開發(fā)深色適配模式編程示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-04-04
  • 分析Android內(nèi)存泄漏的幾種可能

    分析Android內(nèi)存泄漏的幾種可能

    Java內(nèi)存泄漏指的是進(jìn)程中某些對象(垃圾對象)已經(jīng)沒有使用價值了,但是它們卻可以直接或間接地引用到gc roots導(dǎo)致無法被GC回收。本文詳細(xì)羅列了Android內(nèi)存泄漏的八種可能,有需要的可以參考下。
    2016-07-07
  • Android自定義按周簽到打卡功能實(shí)例代碼

    Android自定義按周簽到打卡功能實(shí)例代碼

    這篇文章主要給大家介紹了關(guān)于Android自定義實(shí)現(xiàn)按周簽到打卡功能的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對各位Android開發(fā)者們具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-06-06
  • Android Native庫的加載及動態(tài)鏈接的過程

    Android Native庫的加載及動態(tài)鏈接的過程

    這篇文章主要介紹了Android Native庫的加載及動態(tài)鏈接的加載過程,需要的朋友可以參考下
    2018-01-01
  • Android音頻可視化開發(fā)案例說明

    Android音頻可視化開發(fā)案例說明

    最近移植Android,當(dāng)Android能夠在設(shè)備上面運(yùn)行之后,首先想到的是讓音頻設(shè)備跑起來?!皼]有聲音,再好的戲也出不來”接下來介紹Android音頻可視化開發(fā)流程
    2012-12-12
  • Android實(shí)現(xiàn)將一個Activity設(shè)置成窗口樣式的方法

    Android實(shí)現(xiàn)將一個Activity設(shè)置成窗口樣式的方法

    這篇文章主要介紹了Android實(shí)現(xiàn)將一個Activity設(shè)置成窗口樣式的方法,涉及Android的窗口樣式設(shè)置與布局技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2016-02-02

最新評論

铜山县| 和政县| 唐河县| 日喀则市| 凤庆县| 庆云县| 桐庐县| 新昌县| 巩义市| 天镇县| 英山县| 自治县| 林口县| 科技| 永春县| 卢龙县| 大田县| 汽车| 焉耆| 蕲春县| 南通市| 安康市| 恩施市| 定结县| 康平县| 天门市| 溆浦县| 礼泉县| 广水市| 绿春县| 腾冲县| 潼南县| 册亨县| 策勒县| 通化县| 永福县| 临桂县| 鸡西市| 南召县| 亳州市| 淮南市|