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

Android中l(wèi)istview嵌套scrollveiw沖突的解決方法

 更新時(shí)間:2017年01月25日 10:57:30   作者:墮落8  
這篇文章主要為大家詳細(xì)介紹了Android中l(wèi)istview嵌套scrollveiw沖突的解決方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

一.使用網(wǎng)上用的動(dòng)態(tài)改變listview高度的方法

該方法只適用于item布局是LinearLayout布局的情況,不能是其他的,因?yàn)槠渌腖ayout(如RelativeLayout)沒有重寫onMeasure(),所以會(huì)在onMeasure()時(shí)拋出異常。所以使用限制較大。

public class Utility { 
public static void setListViewHeightBasedOnChildren(ListView listView) { 
//獲取ListView對(duì)應(yīng)的Adapter 
ListAdapter listAdapter = listView.getAdapter();  
if (listAdapter == null) { 
// pre-condition 
return; 
} 
 
int totalHeight = 0; 
for (int i = 0, len = listAdapter.getCount(); i < len; i++) { //listAdapter.getCount()返回?cái)?shù)據(jù)項(xiàng)的數(shù)目 
View listItem = listAdapter.getView(i, null, listView); 
listItem.measure(0, 0); //計(jì)算子項(xiàng)View 的寬高 
totalHeight += listItem.getMeasuredHeight(); //統(tǒng)計(jì)所有子項(xiàng)的總高度 
} 
 
ViewGroup.LayoutParams params = listView.getLayoutParams(); 
params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)); 
//listView.getDividerHeight()獲取子項(xiàng)間分隔符占用的高度 
//params.height最后得到整個(gè)ListView完整顯示需要的高度 
listView.setLayoutParams(params); 
} 
} 

二.網(wǎng)上有帖子說在ScrollView中添加一屬性 android:fillViewport="true" ,這樣就可以讓ListView全屏顯示了。在我機(jī)器上測(cè)試失敗了。

三.重寫ListView、gridView(推薦)

重寫ListView:

public class MyListView extends ListView { 
 
  public MyListView(Context context) { 
    // TODO Auto-generated method stub 
    super(context); 
  } 
 
  public MyListView(Context context, AttributeSet attrs) { 
    // TODO Auto-generated method stub 
    super(context, attrs); 
  } 
 
  public MyListView(Context context, AttributeSet attrs, int defStyle) { 
    // TODO Auto-generated method stub 
    super(context, attrs, defStyle); 
  } 
 
  @Override 
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 
    // TODO Auto-generated method stub 
    int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, 
        MeasureSpec.AT_MOST); 
    super.onMeasure(widthMeasureSpec, expandSpec); 
  } 
} 

重寫GridView:

/** 
 *自定義gridview,解決ScrollView中嵌套gridview顯示不正常的問題(1行) 
 */ 
public class MyGridView extends GridView{ 
   public MyGridView(Context context, AttributeSet attrs) {  
      super(context, attrs);  
    }  
    
    public MyGridView(Context context) {  
      super(context);  
    }  
    
    public MyGridView(Context context, AttributeSet attrs, int defStyle) {  
      super(context, attrs, defStyle);  
    }  
    
    @Override  
    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {  
    
      int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,  
          MeasureSpec.AT_MOST);  
      super.onMeasure(widthMeasureSpec, expandSpec);  
    }  
} 

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

相關(guān)文章

  • RecyclerView的使用之多種Item加載布局

    RecyclerView的使用之多種Item加載布局

    本文給大家介石介紹下如何利用RecyclerView實(shí)現(xiàn)多Item布局的加載,多Item布局的加載的意思就是在開發(fā)過程中List的每一項(xiàng)可能根據(jù)需求的不同會(huì)加載不同的Layout
    2016-03-03
  • Android 創(chuàng)建/驗(yàn)證/刪除桌面快捷方式(已測(cè)試可用)

    Android 創(chuàng)建/驗(yàn)證/刪除桌面快捷方式(已測(cè)試可用)

    桌面快捷方式的出現(xiàn)方便了用戶操作,在某些程度上提高了用戶體驗(yàn),接下來將介紹下Android創(chuàng)建/驗(yàn)證/刪除桌面快捷方式的實(shí)現(xiàn)思路及代碼,感興趣的朋友可以了解下,或許本文可以幫助到你
    2013-02-02
  • Android帶數(shù)字或紅點(diǎn)的底部導(dǎo)航攔和聯(lián)網(wǎng)等待加載動(dòng)畫示例

    Android帶數(shù)字或紅點(diǎn)的底部導(dǎo)航攔和聯(lián)網(wǎng)等待加載動(dòng)畫示例

    這篇文章主要介紹了Android帶數(shù)字或紅點(diǎn)的底部導(dǎo)航攔和聯(lián)網(wǎng)等待加載動(dòng)畫示例,具有一定的參考價(jià)值,有興趣的同學(xué)可以了解一下。
    2017-03-03
  • Android實(shí)現(xiàn)讀取NFC卡的編號(hào)

    Android實(shí)現(xiàn)讀取NFC卡的編號(hào)

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)讀取NFC卡的編號(hào),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-09-09
  • Android項(xiàng)目開發(fā) 教你實(shí)現(xiàn)Periscope點(diǎn)贊效果

    Android項(xiàng)目開發(fā) 教你實(shí)現(xiàn)Periscope點(diǎn)贊效果

    這篇文章主要為大家分享了Android項(xiàng)目開發(fā),一步一步教你實(shí)現(xiàn)Periscope點(diǎn)贊效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2015-12-12
  • 最新評(píng)論

    门头沟区| 红河县| 株洲市| 西吉县| 阿拉尔市| 孝义市| 马公市| 延长县| 巧家县| 民县| 修水县| 正镶白旗| 济阳县| 延津县| 黑山县| 乌拉特后旗| 河南省| 高清| 观塘区| 固始县| 社旗县| 济南市| 称多县| 桦川县| 盐山县| 大荔县| 宝山区| 密山市| 云浮市| 马鞍山市| 西乌珠穆沁旗| 郎溪县| 家居| 岐山县| 广平县| 大姚县| 汝城县| 康马县| 南平市| 米泉市| 房山区|