android.widget.HorizontalScrollView.getWidth()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(10.1k)|赞(0)|评价(0)|浏览(124)

本文整理了Java中android.widget.HorizontalScrollView.getWidth()方法的一些代码示例,展示了HorizontalScrollView.getWidth()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HorizontalScrollView.getWidth()方法的具体详情如下:
包路径:android.widget.HorizontalScrollView
类名称:HorizontalScrollView
方法名:getWidth

HorizontalScrollView.getWidth介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

private final void focusOnView(final HorizontalScrollView scroll, final View view) {
  new Handler().post(new Runnable() {
    @Override
    public void run() {
      int vLeft = view.getLeft();
      int vRight = view.getRight();
      int sWidth = scroll.getWidth();
      scroll.smoothScrollTo(((vLeft + vRight - sWidth) / 2), 0);
    }
  });
}

代码示例来源:origin: hackware1993/MagicIndicator

@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
  if (mAdapter != null) {
    mNavigatorHelper.onPageScrolled(position, positionOffset, positionOffsetPixels);
    if (mIndicator != null) {
      mIndicator.onPageScrolled(position, positionOffset, positionOffsetPixels);
    }
    // 手指跟随滚动
    if (mScrollView != null && mPositionDataList.size() > 0 && position >= 0 && position < mPositionDataList.size()) {
      if (mFollowTouch) {
        int currentPosition = Math.min(mPositionDataList.size() - 1, position);
        int nextPosition = Math.min(mPositionDataList.size() - 1, position + 1);
        PositionData current = mPositionDataList.get(currentPosition);
        PositionData next = mPositionDataList.get(nextPosition);
        float scrollTo = current.horizontalCenter() - mScrollView.getWidth() * mScrollPivotX;
        float nextScrollTo = next.horizontalCenter() - mScrollView.getWidth() * mScrollPivotX;
        mScrollView.scrollTo((int) (scrollTo + (nextScrollTo - scrollTo) * positionOffset), 0);
      } else if (!mEnablePivotScroll) {
        // TODO 实现待选中项完全显示出来
      }
    }
  }
}

代码示例来源:origin: hackware1993/MagicIndicator

PositionData current = mPositionDataList.get(currentIndex);
if (mEnablePivotScroll) {
  float scrollTo = current.horizontalCenter() - mScrollView.getWidth() * mScrollPivotX;
  if (mSmoothScroll) {
    mScrollView.smoothScrollTo((int) (scrollTo), 0);

代码示例来源:origin: OCNYang/QBox

@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
  if (mAdapter != null) {
    mNavigatorHelper.onPageScrolled(position, positionOffset, positionOffsetPixels);
    if (mIndicator != null) {
      mIndicator.onPageScrolled(position, positionOffset, positionOffsetPixels);
    }
    // 手指跟随滚动
    if (mScrollView != null && mPositionDataList.size() > 0 && position >= 0 && position < mPositionDataList.size()) {
      if (mFollowTouch) {
        int currentPosition = Math.min(mPositionDataList.size() - 1, position);
        int nextPosition = Math.min(mPositionDataList.size() - 1, position + 1);
        PositionData current = mPositionDataList.get(currentPosition);
        PositionData next = mPositionDataList.get(nextPosition);
        float scrollTo = current.horizontalCenter() - mScrollView.getWidth() * mScrollPivotX;
        float nextScrollTo = next.horizontalCenter() - mScrollView.getWidth() * mScrollPivotX;
        mScrollView.scrollTo((int) (scrollTo + (nextScrollTo - scrollTo) * positionOffset), 0);
      } else if (!mEnablePivotScroll) {
        // TODO 实现待选中项完全显示出来
      }
    }
  }
}

代码示例来源:origin: OCNYang/QBox

PositionData current = mPositionDataList.get(currentIndex);
if (mEnablePivotScroll) {
  float scrollTo = current.horizontalCenter() - mScrollView.getWidth() * mScrollPivotX;
  if (mSmoothScroll) {
    mScrollView.smoothScrollTo((int) (scrollTo), 0);

代码示例来源:origin: stackoverflow.com

// wrapperLinearLayout being your LinearLayout wrapping the 7 TextViews
wrapperLinearLayout.post(new Runnable() {

  @Override
  public void run() {
    // find out the width of the HorizontalScrollView
    HorizontalScrollView hsv = (HorizontalScrollView) wrapperLinearLayout
        .getParent();
    // the value below will be the new width of all the TextViews so
    // you can see only for initially
    int targetWidth = (hsv.getWidth() / 4) * 7;
    // modify the width of all 7 TextViews
    for (int i = 0; i < wrapperLinearLayout.getChildCount(); i++) {
      LinearLayout.LayoutParams lpc = (android.widget.LinearLayout.LayoutParams) wrapperLinearLayout
          .getChildAt(i).getLayoutParams();
      lpc.width = targetWidth / 7;
    }
  }
});

代码示例来源:origin: com.albedinsky.android/ui-widget-layout-scroll

/**
   */
  @Override
  public boolean isScrolledAtEnd() {
    final View view = mScrollableView.getChildAt(0);
    return view != null && (view.getWidth() - mScrollableView.getWidth()) == mScrollableView.getScrollX();
  }
}

代码示例来源:origin: com.albedinsky.android/ui-widget-layout

/**
   */
  @Override
  public boolean isScrolledAtEnd() {
    final View view = mScrollableView.getChildAt(0);
    return view != null && (view.getWidth() - mScrollableView.getWidth()) == mScrollableView.getScrollX();
  }
}

代码示例来源:origin: com.albedinsky.android/ui

/**
   */
  @Override
  public boolean isScrolledAtEnd() {
    final View view = mScrollableView.getChildAt(0);
    return view != null && (view.getWidth() - mScrollableView.getWidth()) == mScrollableView.getScrollX();
  }
}

代码示例来源:origin: stackoverflow.com

HorizontalScrollView calendarScroller = (HorizontalScrollView)findViewById(R.id.calendarScroller);
 Handler handler=new Handler();
 Runnable mTabSelector = new Runnable() {
   public void run() {
     View tabView = dateScroller.getChildAt(selectedDateIndex);// selected child view
     final int scrollPos = tabView.getLeft() - (calendarScroller.getWidth() - tabView.getWidth()) / 2;
     calendarScroller.smoothScrollTo(scrollPos, 0);
     // mTabSelector = null;
   }
 };
 handler.postDelayed(mTabSelector, 10);

代码示例来源:origin: wanliyang1990/NavigationBar

private void moveBar(View bar, int width, float percent, int position, HorizontalScrollView horizontalScrollView) {
  int w = (int) (position * dip2px(getContext(), twidth) + (dip2px(getContext(), twidth) * percent));
  if (w + horizontalScrollView.getWidth() >= titleLayout.getWidth() + leftm) {
    LayoutParams lp = (LayoutParams) bar.getLayoutParams();
    int marginleft = horizontalScrollView.getWidth() - (length - position) * width + (int) (width * percent);
    lp.width = width - widOffset * 2;
    lp.setMargins(marginleft + widOffset, 0, widOffset, 0);
    bar.requestLayout();
  } else {
    LayoutParams lp = (LayoutParams) bar.getLayoutParams();
    lp.width = width - widOffset * 2;
    lp.setMargins(widOffset + leftm, 0, widOffset, 0);
    bar.requestLayout();
  }
}

代码示例来源:origin: wanliyang1990/NavigationBar

private void moveBar(View bar, int width, float percent, int position, HorizontalScrollView horizontalScrollView) {
  int w = (int) (position * dip2px(getContext(), twidth) + (dip2px(getContext(), twidth) * percent));
  if (w + horizontalScrollView.getWidth() >= titleLayout.getWidth() + leftm) {
    RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) bar.getLayoutParams();
    int marginleft = horizontalScrollView.getWidth() - (length - position) * width + (int) (width * percent);
    lp.width = width - widOffset * 2;
    lp.setMargins(marginleft + widOffset, 0, widOffset, 0);
    bar.requestLayout();
  } else {
    RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) bar.getLayoutParams();
    lp.width = width - widOffset * 2;
    lp.setMargins(widOffset + leftm, 0, widOffset, 0);
    bar.requestLayout();
  }
}

代码示例来源:origin: huangfangyi/FanXin

@Override
  public void run() {
    int mScrollX = tabContainer.getScrollX();
    int childX = (int)ViewCompat.getX(tabContainer.getChildAt(position));
    if(childX < mScrollX){
      scrollView.scrollTo(childX,0);
      return;
    }
    int childWidth = (int)tabContainer.getChildAt(position).getWidth();
    int hsvWidth = scrollView.getWidth();
    int childRight = childX + childWidth;
    int scrollRight = mScrollX + hsvWidth;
    if(childRight > scrollRight){
      scrollView.scrollTo(childRight - scrollRight,0);
      return;
    }
  }
});

代码示例来源:origin: sunhapper/SpEditTool

@Override
 public void run() {
  int mScrollX = tabContainer.getScrollX();
  int childX = (int)tabContainer.getChildAt(position).getX();
  if (childX < mScrollX) {
   scrollView.scrollTo(childX, 0);
   return;
  }
  int childWidth = tabContainer.getChildAt(position).getWidth();
  int hsvWidth = scrollView.getWidth();
  int childRight = childX + childWidth;
  int scrollRight = mScrollX + hsvWidth;
  if (childRight > scrollRight) {
   scrollView.scrollTo(childRight - scrollRight, 0);
   return;
  }
 }
});

代码示例来源:origin: WuXiaolong/WoChat

@Override
  public void run() {
    int mScrollX = tabContainer.getScrollX();
    int childX = (int)ViewCompat.getX(tabContainer.getChildAt(position));
    if(childX < mScrollX){
      scrollView.scrollTo(childX,0);
      return;
    }
    int childWidth = (int)tabContainer.getChildAt(position).getWidth();
    int hsvWidth = scrollView.getWidth();
    int childRight = childX + childWidth;
    int scrollRight = mScrollX + hsvWidth;
    if(childRight > scrollRight){
      scrollView.scrollTo(childRight - scrollRight,0);
      return;
    }
  }
});

代码示例来源:origin: quaap/LaunchTime

private void hscrollOnDrag(View view, DragEvent event, HorizontalScrollView scrollView) {
  float tx = view.getLeft() + event.getX();
  if (isAncestor(scrollView, view)) {
    int thresh = scrollView.getWidth() / 6;
    if (tx < scrollView.getScrollX() + thresh) {
      scrollView.smoothScrollBy(-10, 0);
    } else if (tx > scrollView.getScrollX() + scrollView.getWidth() - thresh) {
      scrollView.smoothScrollBy(10,0);
    }
  }
}

代码示例来源:origin: lzan13/EaseUICustomer

@Override
  public void run() {
    int mScrollX = tabContainer.getScrollX();
    int childX = (int)ViewCompat.getX(tabContainer.getChildAt(position));
    if(childX < mScrollX){
      scrollView.scrollTo(childX,0);
      return;
    }
    int childWidth = (int)tabContainer.getChildAt(position).getWidth();
    int hsvWidth = scrollView.getWidth();
    int childRight = childX + childWidth;
    int scrollRight = mScrollX + hsvWidth;
    if(childRight > scrollRight){
      scrollView.scrollTo(childRight - scrollRight,0);
      return;
    }
  }
});

代码示例来源:origin: stackoverflow.com

// Fix the size of the HorizontalScrollView so it doesn't expand
HorizontalScrollView hsv = (HorizontalScrollView) getDialog().findViewById(R.id.grid_kanji_root);

int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, (float) hsv.getHeight(), getResources().getDisplayMetrics());
int width = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, (float) hsv.getWidth(), getResources().getDisplayMetrics());
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(width, height);

hsv.setLayoutParams(lp);

代码示例来源:origin: goyourfly/EZLedView

@Override
  public void run() {
    scrollView.scrollTo(scrollX, 0);
    scrollX += (ledView.getLedRadius() + ledView.getLedSpace()) * direct;
    if (scrollX <= 0 || scrollX >= ledView.getWidth() - scrollView.getWidth()) {
      direct = -direct;
    }
    handler.postDelayed(this, 10);
  }
});

代码示例来源:origin: stackoverflow.com

private boolean canScroll(HorizontalScrollView horizontalScrollView) {
  View child = (View) horizontalScrollView.getChildAt(0);
  if (child != null) {
    int childWidth = (child).getWidth();
    return horizontalScrollView.getWidth() < childWidth + horizontalScrollView.getPaddingLeft() + horizontalScrollView.getPaddingRight();
  }
  return false;

}

private boolean canScroll(ScrollView scrollView) {
  View child = (View) scrollView.getChildAt(0);
  if (child != null) {
    int childHeight = (child).getHeight();
    return scrollView.getHeight() < childHeight + scrollView.getPaddingTop() + scrollView.getPaddingBottom();
  }
  return false;
}

相关文章

HorizontalScrollView类方法