`

getLayoutParams

阅读更多
利用getLayoutParams()方法和setLayoutParams()方法。
三步曲:
1、首先利用getLayoutParams()方法,获取控件的LayoutParams。
eg:LayoutParams laParams=(LayoutParams)imageView.getLayoutParams();
2、设置该控件的layoutParams参数
eg:     laParams.height=200;
        laParams.width=100;
3、将修改好的layoutParams设置为该控件的layoutParams.
eg:imageView.setLayoutParams(laParams);

http://blog.sina.com.cn/s/blog_6b1079f10100nvsc.html
分享到:
评论

相关推荐

    android 3D相册效果

    final int imageHeight = child.getLayoutParams().height; final int imageWidth = child.getLayoutParams().width; final int rotation = Math.abs(rotationAngle); mCamera.translate(0.0f, 0.0f, 100.0f); ...

    Android layout动态创建

    barHeightLabel.getLayoutParams().height = (int) (dataValues[i] * someScaleFactor); // 设置文字、颜色等 bar.addView(barHeightLabel); } ``` 5. **添加动画效果**: 为了提高用户体验,可以为每个柱形添加...

    GridView左右滑动

    //curPage.getLayoutParams().height = this.getWindowManager().getDefaultDisplay().getHeight() * 2 / 3; for (int i = 0; i ; i++) { //此处动态引用图片资源 info.setImage(R.drawable.g1); //设置图片...

    谷歌开源的Android排版库 FlexboxLayout.zip

    FlexboxLayout.LayoutParams lp = (FlexboxLayout.LayoutParams) view.getLayoutParams(); lp.order = -1; lp.flexGrow = 2; view.setLayoutParams(lp);屏幕截图: 标签:谷歌 google 排版库

    ViewDragHelper使用

    MarginLayoutParams layoutParams = (MarginLayoutParams) child.getLayoutParams(); child.measure(MeasureSpec.makeMeasureSpec(widthSize - layoutParams.leftMargin - layoutParams.rightMargin, MeasureSpec....

    Android自定义布局实现仿qq侧滑部分代码

    contentView.getLayoutParams().width = (int) getScreenWidth(); // ... ``` 接下来,在`onFinishInflate()`方法中,我们确保`SlidingLayout`只有一个父容器,并且该容器只包含两个子视图:左侧菜单和主要内容。...

    Android自定义组件之自动换行View

    LayoutParams lp = (LayoutParams) child.getLayoutParams(); int childWidth = child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin; if (currentLineWidth + childWidth > widthSize) { // 换行 ...

    Android ImageView图片放大到全屏显示

    imageView.getLayoutParams().width = width; imageView.getLayoutParams().height = height; ``` 然后,为了实现局部拉伸放大,我们可以自定义一个ImageView子类,重写其`onTouchEvent()`方法,监听用户的触摸事件...

    自定义组件及其内组件大小的正确设置

    MeasureSpec.makeMeasureSpec(child.getLayoutParams().height, MeasureSpec.EXACTLY); // 测量子视图 child.measure(widthMeasureSpec, heightMeasureSpec); } ``` 除了尺寸设置,还应注意权重分配。例如,在一...

    安卓ImageView水平方向上随着手指来回移动

    setLayoutParams(new LayoutParams(getLayoutParams().width, getLayoutParams().height)); setLeft(getLeft() + dx); initialX = currentX; // 为了防止过度滑动,需要添加边界判断 if (getLeft() ) { ...

    ScrollView中自定义ListView

    ViewGroup.LayoutParams params = getLayoutParams(); params.height = getMeasuredHeight(); } ``` 3. 重写onLayout()方法,根据ScrollView的滚动位置来调整子项的位置。 ```java @Override protected void ...

    点击按钮放大图片.zip

    imageView.getLayoutParams().width *= 2; imageView.getLayoutParams().height *= 2; imageView.requestLayout(); ``` 为了提供更好的用户体验,你还可以考虑使用Animation API来平滑地缩放图片,而不是立即更改...

    android拖动控件,解决回到原点

    ViewGroup.LayoutParams layoutParams = view.getLayoutParams(); // 更新left和top坐标 layoutParams.leftMargin = newX; layoutParams.topMargin = newY; // 设置新的布局参数并请求重绘 view.setLayoutParams...

    android.service.java

    params = SingleLayoutParams.getLayoutParams(); View lay = LayoutInflater.from(this).inflate(R.layout.mylinearlayout, null);// 讲xml问价解析为视图对象 merchant = (TextView) lay.findViewById(R...

    Android加载各种类型布局的宽高参数

    view.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT; // 或其他高度值 ``` 3. **ListView添加头视图** 在Android的ListView中,我们可以添加自定义视图作为列表的头部。这通常用于展示额外的...

    本示例实现利用 XML 布局文件动态创建CheckBox

    dynamicCheckBox.setHeight(templateCheckBox.getLayoutParams().height); dynamicCheckBox.setText(templateCheckBox.getText()); // 添加事件监听器 dynamicCheckBox.setOnCheckedChangeListener(new ...

    android studio VideoView本地视频播放.zip

    ViewGroup.LayoutParams layoutParams = videoView.getLayoutParams(); layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT; layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT; videoView....

    ScroviewDemoListView

    ViewGroup.LayoutParams layoutParams = view.getLayoutParams(); layoutParams.setMarginStart(10); // 左边距 layoutParams.setMarginEnd(10); // 右边距 layoutParams.setMarginTop(10); // 上边距 layoutParams....

    android ImageView网络图片加载、动态设置尺寸、圆角(绝对好用)

    imageView.getLayoutParams().height = (int) (height * 0.3); // 设置为屏幕高度的三成 imageView.requestLayout(); // 强制重绘 ``` 请注意,动态设置尺寸时要考虑到图像的比例,避免拉伸或压缩导致变形。 3....

    google官网自定义控件实例

    int width = getLayoutParams().width; int height = getLayoutParams().height; // 计算并设置控件的实际尺寸 setMeasuredDimension(width, height); } ``` 接着,`onDraw`方法是绘制控件的核心。在这里,...

Global site tag (gtag.js) - Google Analytics