how to set height of relative layout dynamically in android

前端 未结 2 1755
[愿得一人]
[愿得一人] 2021-01-13 08:35

This is working fine on emulator but not on the devices because I have hard coded the height to 365. Can anyone help me in this regard?



        
相关标签:
2条回答
  • 2021-01-13 08:55

    You can change the layout height dynamically through different ways-----

    First,

    getLayoutParams().height= x;
    requestLayout(); or invalidate(); 
    

    Secondly,

     first_tab.setHeight(int pixels);
    

    Try using anyone of the way.......

    0 讨论(0)
  • 2021-01-13 09:00

    You should not use px, use dp instead.

    android:layout_height="365dp"
    

    Have a read here, to know Density independent pixel(dp) better.

    Using dp units to define your application's UI is highly recommended, as a way of ensuring proper display of your UI on different screens.

    0 讨论(0)
提交回复
热议问题