在Android中,可以使用以下方法来获取控件的宽高:
View view = findViewById(R.id.your_view_id);
int width = view.getWidth();
int height = view.getHeight();
View view = findViewById(R.id.your_view_id);
ViewTreeObserver vto = view.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
int width = view.getWidth();
int height = view.getHeight();
// do something with width and height
}
});
通过以上两种方法,就可以在Android中获取到控件的宽高值。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:android如何获取view宽高