2011-06-27 53 views
0

當我嘗試以編程方式設置邊距時,我有一個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); 

謝謝。

回答

0

我忘了回答這個問題。在我的情況下,當ImageView調整大小時,當我使用android:adjustViewBounds屬性設置邊距hand.setLayoutParams(lp);時,它會保持其第一個寬度和高度,從而解決了我的問題。

0

問題出在rlRoot.getMeasuredHeight() - 20rlRoot.getMeasuredHeight()裏面的onCreate方法返回你0.所以rlRoot.getMeasuredHeight()-20意味着你正在減少20個像素的高度。

+0

不,它不在裏面的onCreate方法它是在一個Button單擊事件和getMeasuredHeight代碼返回一個值,我檢查它。 即使它是真的,它不應該改變寬度和高度我把它設置爲imageview的頁邊距值。 –

相關問題