Android
AndroidStudio

LinearLayoutの高さ設定・ScrollViewの高さ設定

More than 3 years have passed since last update.


LinearLayoutの高さ設定


java

LinearLayout linearLayout = (LinearLayout) findViewById(R.id.(iDを設定));

ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams)linearLayout.getLayoutParams();
marginLayoutParams.height = (高さを設定);
linearLayout.setLayoutParams(marginLayoutParams);


ScrollViewの高さ設定


java

ScrollView scrollView = (ScrollView) findViewById(R.id.(iDを設定));

ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams)scrollView.getLayoutParams();
marginLayoutParams.height = (高さを設定);
scrollView.setLayoutParams(marginLayoutParams);


高さ以外の設定

marginLayoutParams.height = (高さを設定);

上記の height 部分を変更すると、

WidthやMarginなども設定できます。