dynamically increase the relative layout size in android

后端 未结 1 946
太阳男子
太阳男子 2021-01-07 13:05

i have a relative layout on which i am displaying a page and some content. when i zoom my page...the layout size is not increasing. i want my layout to increase its size dyn

相关标签:
1条回答
  • 2021-01-07 13:50

    You can do it this way. I also added setting of the margins:

    RelativeLayout targetItem = (RelativeLayout) findViewById(R.id.RelativeLayout01);
    RelativeLayout.LayoutParams adaptLayout = new RelativeLayout.LayoutParams(mWidth, mHeight);
    adaptLayout.setMargins(marginLeft, marginTop, marginRight, marginBottom);   
    targetItem.setLayoutParams(adaptLayout);                    
    

    For mWidth and mHeight you also may set dip values to make it adapt to the different screen sizes. Easy way to do that is to define Dimension in your strings.xml and work with them, not with absolute values.

    So, if you define relative_width as 120dip, and relative_height as 100 dip then in code you have

    RelativeLayout.LayoutParams adaptLayout = new RelativeLayout.LayoutParams(getResources().getDimension(R.dimen.relative_width), getResources().getDimension(R.dimen.relative_height));
    
    0 讨论(0)
提交回复
热议问题