
//取控件当前的布局参数
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) imageView.getLayoutParams()
//设置宽度值
params.width = dip2px(MainActivity.this, width)
//设置高度值
params.height = dip2px(MainActivity.this, height)
//使设置好的布局参数应用到控件
imageView.setLayoutParams(params)
1
2
3
4
5
6
7
8
1
2
3
4
5
6
7
8
高度除了可以设置成以上固定的值,也可以设置成wrap_content或match_content
ViewGroup.LayoutParams.WRAP_CONTENT
ViewGroup.LayoutParams.MATCH_PARENT
1
2
1
2
在这里插入图片描述
xml
Android ExoPlayer可以使用`setVideoScalingMode(int mode) `方法来设置视频固定宽高大小,其中mode有3种值:VideoScalingMode.SCALE_TO_FIT:保持视频原始比例,但将视频显示在可用的区域里;VideoScalingMode.SCALE_TO_FIT_WITH_CROPPING:保持视频原始比例,但将视频裁剪以适应可用的区域;VideoScalingMode.SCALE_TO_MATCH_PARENT:将视频拉伸至可用的区域。在对应的控件中使用android:layout_width标签即可。
android:layout_width标签中可以使用match_parent常量使控件尺寸与其上级组件尺寸相同
可以使用wrap_content使控件尺寸刚好包裹住内容
也可以使用px(像素)、pt(磅)、dp(密度)、sp(可伸缩像素)作为单位,从而设置控件的宽度:
例如:
<EditTextandroid:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="one"
android:layout_gravity="right"/>
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)