Set view height and width

3103 단어 androidlayoutDPViewDP
view.getLayoutParams().height = 20; //px
// If you're setting the height after the layout has already been 'laid out', 
// make sure you also call:
view.requestLayout();
// getLayout() will fail with null-exception
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(100, 100); // px
view.setLayoutParams(layoutParams);
int dimensionInDp = (int) TypedValue.applyDimension(
		TypedValue.COMPLEX_UNIT_DIP, 
        	dimensionInPixel, 
        	getResources().getDisplayMetrics());

https://stackoverflow.com/questions/3144940/set-imageview-width-and-height-programmatically

좋은 웹페이지 즐겨찾기