當我嘗試以編程方式設置邊距時,我有一個ImageView,它的src是一個動畫列表,它也調整了非常小的imageview大小。RelativeLayout MarginLayoutParams調整ImageView的大小非常小
ImageView hand = (ImageView)rlRoot.findViewById(R.id.ivHandAnimation);
MarginLayoutParams marginsParams = new MarginLayoutParams(hand.getLayoutParams());
marginsParams.setMargins(this.getLeft(), rlRoot.getMeasuredHeight() - 20, 0, 0);
RelativeLayout.LayoutParams lp = new LayoutParams(marginsParams);
//lp.height = rlRoot.findViewById(R.id.btnHole_14).getMeasuredHeight();
hand.setLayoutParams(lp);
if (hand != null) {
hand.setVisibility(View.VISIBLE);
AnimationDrawable frameAnimation = (AnimationDrawable)hand.getDrawable();
frameAnimation.setCallback(hand);
frameAnimation.setVisible(true, true);
}
我試圖設置lp.height但它不工作。我還使用以下代碼創建LayoutParams。
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
謝謝。
不,它不在裏面的onCreate方法它是在一個Button單擊事件和getMeasuredHeight代碼返回一個值,我檢查它。 即使它是真的,它不應該改變寬度和高度我把它設置爲imageview的頁邊距值。 –