Reputation: 11768
I want the scrollview to fit half of my screen regardless of the android device it's running...how can i do that dynamically . I tried something like this but i am stuck
Display display = ((WindowManager) getSystemService(this.WINDOW_SERVICE)).getDefaultDisplay();
int displayHeight = display.getHeight();
Log.w("DHA","test 3");
ScrollView sv = (ScrollView)findViewById(R.id.ScrollView01);
Log.w("DHA","test 2");
sv.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, displayHeight - 10));
The application closes unexpectedly after the last line
Upvotes: 0
Views: 163
Reputation: 627
try this this might help you..:)
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
Log.v("arpit", "dm width" + dm.widthPixels + "dm heigth"
+ dm.heightPixels);
widt = dm.widthPixels;
hight = dm.heightPixels
LayoutParams params= new LayoutParams(
widt/2 ,hight/2);
Upvotes: 1