Android, add view with height in percentage
问题 i wanna add a view with a 100% width and X%(e.g: lets make it 40%) to the parent view i have this: private RelativeLayout getParentView(){ return (RelativeLayout) MyActivity.this.getWindow().getDecorView().getRootView(); } i should cast parent view to LinearLayout or RelativeLayout can achieve this ? and how to set 'myView' width and height in percentage programmatically ? Thanks 回答1: You can do this by simply getting the screen width public static int getScreenWidth(Context context) {