1
如何以編程方式設置GestureOverlayView's
寬度和高度?以編程方式設置GestureOverlayView的寬度和高度?
我試過下面的代碼。但是在設置寬度和高度時出現空指針異常。
GestureOverlayView gestureOverlayView = new GestureOverlayView(this);
View inflate = getLayoutInflater().inflate(R.layout.main, null);
ImageView imageView = (ImageView) inflate.findViewById(R.id.imageView);
gestureOverlayView.addView(inflate);
gestureOverlayView.getLayoutParams().height = 50;
gestureOverlayView.getLayoutParams().width = 50;
setContentView(gestureOverlayView);
感謝您的回覆。你提到「你需要首先添加視圖才能讀出高度和寬度」是正確的。我只是改變我的代碼如下。這個對我有用。 setContentView(gestureOverlayView); gestureOverlayView.getLayoutParams()。height = 50; gestureOverlayView.getLayoutParams()。width = 50; – SKK
歡迎您:) – rekire