0

I want to get my layout or view (not screen size) width an height in some android devices, so how can I do this? For example:

<LinearLayout
     android:orientation="vertical"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:layout_weight="1"
     android:paddingRight="8dp"
     android:paddingLeft="8dp"
     android:id="@+id/layout_scrol_left"/>

I have this layout and I want to get layout width and height size (in dip) in runtime, how can I do that?

  • possibly relate this https://stackoverflow.com/questions/21926644/get-height-and-width-of-a-layout-programmatically – Atik Faysal Jun 11 '23 at 10:31

1 Answers1

0

val myView = findViewById<View>(R.id.my_view)
val layoutParams = myView.layoutParams
layoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT
layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT
layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT
layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT
myView.layoutParams = layoutParams
Ani
  • 1
  • 1