2011-06-27 9 views
0

私はImageViewを持っていて、その余白をプログラムで設定しようとすると、そのsrcはアニメーションリストになっています。RelativeLayout MarginLayoutParams resize 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のサイズを変更すると、余白を設定すると最初の幅と高さが維持されますhand.setLayoutParams(lp); プロパティを使用して私の問題を修正しました。

0

問題はrlRoot.getMeasuredHeight() - 20です。 rlRoot.getMeasuredHeight() onCreateメソッドは0を返します。したがって、rlRoot.getMeasuredHeight()-20は、高さを20ピクセル減らすことを意味します。

+0

いいえ内部には作成されていませんボタンのクリックイベントにあり、getMeasuredHeightコードは値を返します。 でも、それが幅と高さを変えてはいけません。イメージビューの余白の上限値に設定しました。 –

関連する問題