2016-07-08 7 views
0

私はのViewGroupを拡張してカスタムのViewGroupを作成したが、私はLayoutParamsにアクセスできるにもかかわらず、私は、そのオブジェクトのsetMargins属性を使用するように見えることはできません。setMargins()を呼び出す方法。アンドロイドのカスタムViewGroupで?

+1

の最も可能性の高い複製(http://stackoverflow.com/questions/33317439/setmargins-method-is-カスタムビューグループで作業していない) –

答えて

0
LayoutParams params = new LayoutParams(
     LayoutParams.WRAP_CONTENT,  
     LayoutParams.WRAP_CONTENT); 

params.setMargins(left, top, right, bottom); 
yourView.setLayoutParams(params); 

希望しますように!

0

LayoutParamsnullではありません)にアクセスできる場合は、MarginLayoutParamsにキャストしてみてください。 [方法は、カスタムのViewGroupに動作していないsetMargins]のLayoutParams(例えばLinearLayout.LayoutParamsRelativeLayout.LayoutParamsMarginLayoutParamsを拡張)

MarginLayoutParams params = (MarginLayoutParams) getLayoutParams(); 
params.setMargins(left, top, right, bottom); 
requestLayout(); 
関連する問題