android中设置一些没有maxHeight属性控件的最高值
16lz
2022-06-12
控件如下
写一个类
public class OnViewGlobalLayoutListener implements ViewTreeObserver.OnGlobalLayoutListener { private int maxHeight = 500; private View view; public OnViewGlobalLayoutListener(View view, int height) { this.view = view; this.maxHeight = height; } @Override public void onGlobalLayout() { if (view.getHeight() > maxHeight) view.getLayoutParams().height = maxHeight; } }
设置如下:
View view = findViewById(R.id.devicelist_layout); view.getViewTreeObserver().addOnGlobalLayoutListener(new OnViewGlobalLayoutListener(view, 300));
转自:https://blog.haloxin.me/post/100.html
更多相关文章
- Android进程回收
- android 状态栏占位_Android(安卓)Studio 全屏沉浸式透明状态栏
- 【Android程序开发】EditText详解
- Android(安卓)兼容性测试(CTS)
- Android(安卓)layout_alignBottom 注意事项
- Android(安卓)View And Activity
- Android
- 多个控件跑马灯效果
- Android(安卓)控件 —— ListView