欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

總結(jié)ScrollView中嵌套ListView/GridView的方法

一、ScrollView中嵌套ListView/GridView:

創(chuàng)新互聯(lián)建站從2013年開始,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目網(wǎng)站設(shè)計(jì)制作、做網(wǎng)站網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢想脫穎而出為使命,1280元井研做網(wǎng)站,已為上家服務(wù),為井研各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話:18982081108

     方法一:計(jì)算ListView的高度

public static void setListViewHeightBasedOnChildren(ListView listView) {
  ListAdapter listAdapter = listView.getAdapter();
  if (listAdapter == null) {
   // pre-condition
   return;
  }
  int totalHeight = 0;
  for (int i = 0; i < listAdapter.getCount(); i++) {
   View listItem = listAdapter.getView(i, null, listView);
   listItem.measure(0, 0);
   totalHeight += listItem.getMeasuredHeight();
  }
  ViewGroup.LayoutParams params = listView.getLayoutParams();
  params.height = totalHeight
    + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
  listView.setLayoutParams(params);
 }

     處理方式:在將樓上這個(gè)方法拷貝到工具類中,在ListVIew.setAdapter 的下方調(diào)用這個(gè)方法即可,如下所示:

apprAdapter = new ApprovedPersonAdapter(mContext, mListAped);
mListView.setAdapter(apprAdapter);
ListHeightUtils.setListViewHeightBasedOnChildren(mListView);

   

    方法二:重寫ListView/GridView

    重寫ListView:

public class MyScrollVListView extends ListView {

 public MyScrollVListView(Context context) {
  super(context);
  // TODO Auto-generated constructor stub
 }

 public MyScrollVListView(Context context, AttributeSet attrs) {
  super(context, attrs);
 }

 public MyScrollVListView(Context context, AttributeSet attrs, int defStyle) {
  super(context, attrs, defStyle);
 }

 @Override
 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
  int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
    MeasureSpec.AT_MOST);
  super.onMeasure(widthMeasureSpec, expandSpec);
 }

}

    重寫GridView:

public class MyScrollGridView extends GridView {  
    private boolean haveScrollbar = false;  
    public MyScrollGridView(Context context) {  
        super(context);  
    }  
    public MyScrollGridView(Context context, AttributeSet attrs) {  
        super(context, attrs);  
    }  
    public MyScrollGridView(Context context, AttributeSet attrs, int defStyle) {  
        super(context, attrs, defStyle);  
    }  
    /** 
     * 設(shè)置是否有ScrollBar,當(dāng)要在ScollView中顯示時(shí),應(yīng)當(dāng)設(shè)置為false。 默認(rèn)為 true 
     *  
     * @param haveScrollbars 
     */  
    public void setHaveScrollbar(boolean haveScrollbar) {  
        this.haveScrollbar = haveScrollbar;  
    }  
   
    @Override  
    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {  
  
        int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,  
                MeasureSpec.AT_MOST);  
        super.onMeasure(widthMeasureSpec, expandSpec);  
    }
   
}

     處理方式:和正常的布局ListView/GridView一樣,只是這里需要用全路徑,即可解決,如下所示:

<com.derek.views.MyScrollVListView
        android:id="@+id/mListView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >
    </com.derek.views.MyScrollVListView>

 

    方法三:LinerLayout代替ListView/GridView

    1、先在需要布局ListView/GridView的地方布局上一個(gè)LinerLayout,如下所示:

 <LinearLayout

            android:id="@+id/mLinearLayout"

            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical|center_horizontal"
            android:adjustViewBounds="true"
            android:background="#85808c"
            android:orientation="vertical" >
 </LinearLayout>

      2、在FindViewById該對象,如下所示:

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

      3、初始化數(shù)據(jù)

/**
  * 動態(tài)添加數(shù)據(jù)
  * @param jSONArrayOps
  */
 private void initGridView(JSONArray jSONArrayOps) {
  mLinearLayout.removeAllViews();
  
  ArrayList<HashMap<String, Object>> lstItem = getOptionData();
  SimpleAdapter saImageAdapter = new SimpleAdapter(mContext,
    lstItem,// 數(shù)據(jù)源
                R.layout.item_gridview_button,// 顯示布局
                new String[] {"itemText" },
                new int[] {  R.id.mBtnItemText });
  
  mGridViewButton = new SquareGridView(mContext);
  mGridViewButton.setAdapter(saImageAdapter);
  int size = JSONArrayOps.length();
  int numColumns = 0;
  if (size%2 == 0) {
   numColumns = 2;
  }else if(size%3 == 0){
   numColumns = 3;
  }else{
   numColumns = 2;
  }
  mGridViewButton.setNumColumns(numColumns);
//  mGridViewButton.setColumnWidth(120);
  mGridViewButton.setGravity(Gravity.CENTER);
  mGridViewButton.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
  //去掉點(diǎn)擊效果的背景
  mGridViewButton.setSelector(new ColorDrawable(Color.TRANSPARENT));
  mGridViewButton.setVerticalSpacing(DensitydiUtil
    .dip2px(mContext, 3));
  int heigth = (int) getResources().getDimension(R.dimen.height_26_80);
  if (size <= 2) {
   mGridViewButton.setLayoutParams(new LinearLayout.LayoutParams(
     LayoutParams.FILL_PARENT, heigth/2));
  } else {
   mGridViewButton.setLayoutParams(new LinearLayout.LayoutParams(
     LayoutParams.FILL_PARENT, heigth));
  }
  /**監(jiān)聽事件**/
  mGridViewButton.setOnItemClickListener(new OnItemClickListener() {

   @Override
   public void onItemClick(AdapterView<?> parent, View view,
     int position, long id) {
    String data = edtContent.getText().toString();
    //***賦值的目的是為了點(diǎn)擊拒絕時(shí)能促發(fā)后臺修改數(shù)據(jù)**//*
    if (TextUtils.isEmpty(data)) {
     data = mContext.getResources().getString(R.string.strAppApproval);
    }
    try {
     String mName = JSONArrayOps.getString(position);
     requestApprovalData( mName,data);
     Tools.printInfo(mName);
    } catch (JSONException e) {
     e.printStackTrace();
    }
   }
  });
//   new LayoutParam(LayoutParam.FILL_PARENT, LayoutParam.FILL_PARENT)
  mLinearLayout.addView(mGridViewButton);
 }

    如此將數(shù)據(jù)組裝好后,該問題也基本解決了,mLinearLayout.removeAllViews();
表示先清空所有的View,便于每次添加進(jìn)去的都是新的View。此方法在很多動態(tài)添加數(shù)據(jù)中都會用上,ListView的方法與此一樣。

二、ScrollView嵌套ListView時(shí),嵌套的布局是A布局+ListView+B布局的形式,當(dāng)A布局中的內(nèi)容超過一屏?xí)r,ListView的最后一個(gè)Item總是顯示不全?

  解決方案: (1)ListView不能用自定義的,必須用原生的ListView;

         (2)ListView的寬高都用 match_parent或fill_parent;

         (3)用計(jì)算高度的方式去實(shí)現(xiàn)setListViewHeightBasedOnChildren(ListView);

         (4)adapter的item的根布局必須為LinearLayout布局,不然計(jì)算高度時(shí)會有問題;

         (5)ScrollView中添加屬性 android:fillViewport="true"

  利用以上的5點(diǎn),基本可以解決問題,我是這樣解決,如果有沒有解決的,請注意布局上看看有什么問題,把多余的功能去掉,從最基本的只顯示ListView開始調(diào)節(jié),一個(gè)功能一個(gè)功能的加上去,看看是哪里出問題,就逐步排除并解決。

     ListView中嵌套ListView的處理在后續(xù)的文章中單獨(dú)講解,其實(shí)這三種方法網(wǎng)上也基本有的,只是便于android的學(xué)習(xí)記錄一下這個(gè)過程。

分享名稱:總結(jié)ScrollView中嵌套ListView/GridView的方法
URL網(wǎng)址:http://chinadenli.net/article36/joijsg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站策劃、移動網(wǎng)站建設(shè)、虛擬主機(jī)網(wǎng)站收錄、響應(yīng)式網(wǎng)站定制開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)
国产传媒精品视频一区| 亚洲最大福利在线观看| 国产性色精品福利在线观看| 久久中文字幕中文字幕中文| 最新日韩精品一推荐日韩精品| 狠色婷婷久久一区二区三区| 国产av大片一区二区三区| 福利视频一区二区在线| 欧美日韩精品一区二区三区不卡| 亚洲国产日韩欧美三级| 久久精品欧美一区二区三不卡| 后入美臀少妇一区二区| 99久久精品视频一区二区| 亚洲欧洲在线一区二区三区| 日韩亚洲精品国产第二页| 国产精品视频一区二区秋霞| 久久精品国产亚洲av麻豆尤物| 91精品国产综合久久福利| 国产精品99一区二区三区| 精品少妇人妻av一区二区蜜桃 | 日本高清一道一二三区四五区 | 日本福利写真在线观看| 日本亚洲欧美男人的天堂| 麻豆看片麻豆免费视频| 欧美日韩一区二区午夜| 在线亚洲成人中文字幕高清| 精品一区二区三区人妻视频| 亚洲欧美日本国产有色| 区一区二区三中文字幕| 欧美日韩国产精品自在自线| 久久精品一区二区少妇| 夫妻性生活一级黄色录像| 亚洲国产四季欧美一区| 日韩aa一区二区三区| 亚洲国产av一二三区| 日本亚洲欧美男人的天堂| 中文字幕av诱惑一区二区| 亚洲最新中文字幕一区| 久久国产精品亚州精品毛片| 视频一区二区三区自拍偷| 亚洲国产精品一区二区|