opc0de
opc0de

Reputation: 11768

Adjust scrollview dynamically

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

Answers (1)

Prashant Mishra
Prashant Mishra

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

Related Questions