下面列出了android.widget.LinearLayout#getMeasuredHeight ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void createBottomLogoLayout() {
mLL = new LinearLayout(EventDetailActivity.this);
mLL.setBackgroundColor(ContextCompat.getColor(EventDetailActivity.this, R.color.window_background));
ViewGroup.LayoutParams LLParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 100);
mLL.setLayoutParams(LLParams);
mLL.setOrientation(LinearLayout.HORIZONTAL);
mLL.setPadding(24, 0, 0, 0);
mLL.setGravity(Gravity.CENTER_VERTICAL);
ImageView icon = new ImageView(EventDetailActivity.this);
icon.setScaleType(ImageView.ScaleType.CENTER_CROP);
icon.setImageDrawable(ContextCompat.getDrawable(EventDetailActivity.this, R.mipmap.ic_launcher));
mLL.addView(icon);
TextView hb = new TextView(EventDetailActivity.this);
hb.setText("@心动小分队");
mLL.addView(hb);
mLL.measure(View.MeasureSpec.makeMeasureSpec(mWidth, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
mHeight += mLL.getMeasuredHeight();
}
/**
* 添加下拉刷新的HeadView
*
* @date 2015年2月14日 上午11:17
* @change hillfly
*/
private void addHeadView() {
mHeadView = (LinearLayout) mInflater.inflate(R.layout.listview_multilistview_head, null);
mArrowImageView = (ImageView) mHeadView.findViewById(R.id.head_arrowImageView);
mArrowImageView.setMinimumWidth(70);
mArrowImageView.setMinimumHeight(50);
mProgressBar = (ProgressBar) mHeadView.findViewById(R.id.head_progressBar);
mTipsTextView = (TextView) mHeadView.findViewById(R.id.head_tipsTextView);
mLastUpdatedTextView = (TextView) mHeadView.findViewById(R.id.head_lastUpdatedTextView);
measureView(mHeadView);
mHeadViewHeight = mHeadView.getMeasuredHeight();
mHeadView.setPadding(0, -1 * mHeadViewHeight, 0, 0);
mHeadView.invalidate();
addHeaderView(mHeadView, null, false);
mHeadState = DONE;
}
/**
* 显示底部弹出菜单
*/
private void showPopDialog() {
LayoutInflater inflater = LayoutInflater.from(this);
mCameradialog = new Dialog(this, R.style.BottomDialog);
LinearLayout root = (LinearLayout) inflater.from(this).inflate(R.layout.pop_menu,null);
root.findViewById(R.id.takePic).setOnClickListener(this);
root.findViewById(R.id.takeGallery).setOnClickListener(this);
root.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mCameradialog.cancel();
}
});
mCameradialog.setContentView(root);
Window dialogWindow = mCameradialog.getWindow();
dialogWindow.setGravity(Gravity.BOTTOM);
// dialogWindow.setWindowAnimations(R.style.dialogstyle); // 添加动画
WindowManager.LayoutParams lp = dialogWindow.getAttributes(); // 获取对话框当前的参数值
lp.x = 0; // 新位置X坐标
lp.y = 0; // 新位置Y坐标
lp.width = (int) getResources().getDisplayMetrics().widthPixels; // 宽度
root.measure(0, 0);
lp.height = root.getMeasuredHeight();
lp.alpha = 9f; // 透明度
dialogWindow.setAttributes(lp);
mCameradialog.show();
}
/**
* 添加下拉刷新的HeadView
* @date 2013-11-11 下午9:48:26
* @change JohnWatson
* @version 1.0
*/
private void addHeadView() {
mHeadView = (LinearLayout) mInflater.inflate(R.layout.head, null);
mArrowImageView = (ImageView) mHeadView
.findViewById(R.id.head_arrowImageView);
mArrowImageView.setMinimumWidth(70);
mArrowImageView.setMinimumHeight(50);
mProgressBar = (ProgressBar) mHeadView
.findViewById(R.id.head_progressBar);
mTipsTextView = (TextView) mHeadView.findViewById(
R.id.head_tipsTextView);
mLastUpdatedTextView = (TextView) mHeadView
.findViewById(R.id.head_lastUpdatedTextView);
measureView(mHeadView);
mHeadViewHeight = mHeadView.getMeasuredHeight();
mHeadViewWidth = mHeadView.getMeasuredWidth();
mHeadView.setPadding(0, -1 * mHeadViewHeight, 0, 0);
mHeadView.invalidate();
Log.v("size", "width:" + mHeadViewWidth + " height:"
+ mHeadViewHeight);
addHeaderView(mHeadView, null, false);
mHeadState = DONE;
}
/***
* 初始化头部
*/
private void initHeadView() {
inflater = LayoutInflater.from(context);
mHeadView = (LinearLayout) inflater.inflate(
R.layout.pulldownlistview_head, null);
mArrowImageView = (ImageView) mHeadView
.findViewById(R.id.pulldownlistview_head_arrow_ImageView);
mArrowImageView.setMinimumWidth(50);
mArrowImageView.setMinimumHeight(50);
mHeadProgressBar = (ProgressBar) mHeadView
.findViewById(R.id.pulldownlistview_head_progressBar);
mRefreshTextview = (TextView) mHeadView
.findViewById(R.id.pulldownlistview_head_tips_TextView);
mLastUpdateTextView = (TextView) mHeadView
.findViewById(R.id.pulldownlistview_head_lastUpdated_TextView);
headContentOriginalTopPadding = mHeadView.getPaddingTop();
measureView(mHeadView);
headContentHeight = mHeadView.getMeasuredHeight();
headContentWidth = mHeadView.getMeasuredWidth();
mHeadView.setPadding(mHeadView.getPaddingLeft(),
-1 * headContentHeight, mHeadView.getPaddingRight(),
mHeadView.getPaddingBottom());
mHeadView.invalidate();
// LOG.D("初始高度:"+headContentHeight);
// LOG.D("初始TopPad:"+headContentOriginalTopPadding);
addHeaderView(mHeadView);
setOnScrollListener(this);
}
private void init(Context context) {
//设置滑动效果
animation = new RotateAnimation(0, -180,
RotateAnimation.RELATIVE_TO_SELF, 0.5f,
RotateAnimation.RELATIVE_TO_SELF, 0.5f);
animation.setInterpolator(new LinearInterpolator());
animation.setDuration(100);
animation.setFillAfter(true);
reverseAnimation = new RotateAnimation(-180, 0,
RotateAnimation.RELATIVE_TO_SELF, 0.5f,
RotateAnimation.RELATIVE_TO_SELF, 0.5f);
reverseAnimation.setInterpolator(new LinearInterpolator());
reverseAnimation.setDuration(100);
reverseAnimation.setFillAfter(true);
inflater = LayoutInflater.from(context);
headView = (LinearLayout) inflater.inflate(R.layout.pull_to_refresh_head, null);
arrowImageView = (ImageView) headView.findViewById(R.id.head_arrowImageView);
arrowImageView.setMinimumWidth(50);
arrowImageView.setMinimumHeight(50);
progressBar = (ProgressBar) headView.findViewById(R.id.head_progressBar);
tipsTextview = (TextView) headView.findViewById(R.id.head_tipsTextView);
lastUpdatedTextView = (TextView) headView.findViewById(R.id.head_lastUpdatedTextView);
headContentOriginalTopPadding = headView.getPaddingTop();
measureView(headView);
headContentHeight = headView.getMeasuredHeight();
headContentWidth = headView.getMeasuredWidth();
headView.setPadding(headView.getPaddingLeft(), -1 * headContentHeight, headView.getPaddingRight(), headView.getPaddingBottom());
headView.invalidate();
//System.out.println("初始高度:"+headContentHeight);
//System.out.println("初始TopPad:"+headContentOriginalTopPadding);
addHeaderView(headView);
setOnScrollListener(this);
}
private void init(Context context) {
// Load all of the animations we need in code rather than through XML
mFlipAnimation = new RotateAnimation(0, 180,
RotateAnimation.RELATIVE_TO_SELF, 0.5f,
RotateAnimation.RELATIVE_TO_SELF, 0.5f);
mFlipAnimation.setInterpolator(new LinearInterpolator());
mFlipAnimation.setDuration(250);
mFlipAnimation.setFillAfter(true);
mReverseFlipAnimation = new RotateAnimation(180, 360,
RotateAnimation.RELATIVE_TO_SELF, 0.5f,
RotateAnimation.RELATIVE_TO_SELF, 0.5f);
mReverseFlipAnimation.setInterpolator(new LinearInterpolator());
mReverseFlipAnimation.setDuration(250);
mReverseFlipAnimation.setFillAfter(true);
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
mRefreshView = (LinearLayout) mInflater.inflate(
R.layout.widget_pull_to_refresh_header, null);
mRefreshViewText =
(TextView) mRefreshView.findViewById(R.id.pull_to_refresh_text);
mRefreshViewImage =
(ImageView) mRefreshView.findViewById(R.id.pull_to_refresh_image);
mRefreshViewProgress =
(ProgressBar) mRefreshView.findViewById(R.id.pull_to_refresh_progress);
mRefreshViewLastUpdated =
(TextView) mRefreshView.findViewById(R.id.pull_to_refresh_updated_at);
Theme theme = new Theme(context);
mRefreshViewText.setTextColor(theme.getColor("content"));
mRefreshViewImage.setMinimumHeight(50);
mRefreshView.setOnClickListener(new OnClickRefreshListener());
mRefreshOriginalTopPadding = mRefreshView.getPaddingTop();
mRefreshState = TAP_TO_REFRESH;
addHeaderView(mRefreshView);
super.setOnScrollListener(this);
measureView(mRefreshView);
mRefreshViewHeight = mRefreshView.getMeasuredHeight();
}
private ScrollView createDropDownView() {
final LinearLayout dropdownView = new LinearLayout(getContext());
ScrollView scrollView = new ScrollView(getContext());
int clickableChildCounter = 0;
dropdownView.setOrientation(LinearLayout.VERTICAL);
int height = (int) (itemHeight * bootstrapSize);
LayoutParams childParams = new LayoutParams(LayoutParams.MATCH_PARENT, height);
for (String text : dropdownData) {
TextView childView = new TextView(getContext());
childView.setGravity(Gravity.CENTER_VERTICAL);
childView.setLayoutParams(childParams);
int padding = (int) (baselineItemLeftPadding * bootstrapSize);
childView.setPadding(padding, 0, padding, 0);
childView.setTextSize(baselineDropDownViewFontSize * bootstrapSize);
childView.setTextColor(ColorUtils.resolveColor(android.R.color.black, getContext()));
Drawable background = getContext().obtainStyledAttributes(null, new int[]{
android.R.attr.selectableItemBackground}, 0, 0)
.getDrawable(0);
ViewUtils.setBackgroundDrawable(childView, background);
childView.setTextColor(BootstrapDrawableFactory.bootstrapDropDownViewText(getContext()));
childView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dropdownWindow.dismiss();
if (onDropDownItemClickListener != null) {
onDropDownItemClickListener.onItemClick(dropdownView, v, v.getId());
}
}
});
if (Pattern.matches(SEARCH_REGEX_HEADER, text)) {
childView.setText(text.replaceFirst(REPLACE_REGEX_HEADER, ""));
childView.setTextSize((baselineDropDownViewFontSize - 2F) * bootstrapSize);
childView.setClickable(false);
childView.setTextColor(ColorUtils.resolveColor(R.color.bootstrap_gray_light,
getContext()));
}
else if (Pattern.matches(SEARCH_REGEX_SEPARATOR, text)) {
childView = new DividerView(getContext());
childView.setClickable(false);
childView.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 3));
}
else if (Pattern.matches(SEARCH_REGEX_DISABLED, text)) {
childView.setEnabled(false);
childView.setId(clickableChildCounter++);
childView.setText(text.replaceFirst(REPLACE_REGEX_DISABLED, ""));
}
else {
childView.setText(text);
childView.setId(clickableChildCounter++);
}
dropdownView.addView(childView);
}
dropdownView.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
dropDownViewHeight = dropdownView.getMeasuredHeight();
dropDownViewWidth = dropdownView.getMeasuredWidth();
scrollView.setVerticalScrollBarEnabled(false);
scrollView.setHorizontalScrollBarEnabled(false);
scrollView.addView(dropdownView);
cleanData();
return scrollView;
}