0

各リスト項目にはhorizontal list、リストビュー内の別のビュー (ボトルオーバーレイ) の高さの特定の割合であると想定される背景塗りつぶしビューがあります。

this questiongetHeight() で述べたように、ボトルオーバーレイビューの高さが見つからないことを除いて、すべて機能します。提案されているように onGlobalLayout リスナーを使用しようとしましたが、設定時に使用される値に関係なく、すべてのアイテムの塗りつぶしの高さは同じです layoutparams.height

これを行う簡単な方法はありますかbottleheightoverlay。リスト内の各項目で同じです。

public class ImageAdapter extends BaseAdapter {

// varible declaration... 

// getView that displays the data at the specified position in the data set.
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
       ......
       ......
      //increase height of filler
      int bottleHeight =  gridView.findViewById(R.id.bottleoverlay).getHeight();
      FrameLayout backgroundfill = (FrameLayout) gridView.findViewById(R.id.backroundfillbar);

      double percent =  products.get(position).value/ products.get(0).value;
      backgroundfill.getLayoutParams().height = (int) ( (bottleHeight/percent));
4

1 に答える 1

0

私はgloballayoutリスナーを使用して動作させました。これはimageAdapterの私のものです

      if(!heightSet ){

      final LinearLayout tv = (LinearLayout) gridView.findViewById(R.id.bottleover);
       ViewTreeObserver vto = tv.getViewTreeObserver();
      vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

          @Override
          public void onGlobalLayout() {

              bottleheight = tv.getHeight();
              heightSet = true;
              System.out.println("bottle hiegiht " + bottleheight);
              //turn off listenter
              ViewTreeObserver obs = tv.getViewTreeObserver();

              if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                  obs.removeOnGlobalLayoutListener(this);
              } else {
                  obs.removeGlobalOnLayoutListener(this);
              }
          }

      });
      }
于 2013-07-19T08:33:33.570 に答える