https://kotlinlang.org logo
t

The Monster

08/12/2021, 1:15 AM
How is this View inflated? Is TextView a field of LinearLayout or gets moved somewhere?
Copy code
xml
<LinearLayout xmlns:android="<http://schemas.android.com/apk/res/android>"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <TextView
        android:id="@+id/item_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>
google 1
😶 4
stackoverflow 1
l

Luis

08/12/2021, 2:17 AM
Not sure what else you are asking, but the text view becomes a child of the linear layout during inflation. Usually you would access views via
findViewById()
in your activity or fragment.
t

The Monster

08/12/2021, 3:12 AM
I meant like, after the TextView is inflated(turned into Java objects), does it get added as a property of the LinearLayout object or not? Maybe added into a data structure inside LinearLayout?
k

Kirill Grouchnikov

08/12/2021, 4:18 AM
If you're interested in how this works under the hood, you'd look at the source code of LayoutInflater (around lines 627-690) and ViewGroup (around lines 5338-5366). The 😶 tag means that this, though, has nothing to do with the purpose of this channel, and questions like this do not get much traction 99% of the time.
l

Luis

08/12/2021, 5:55 AM
Yep, you can use cs.android.com to search for sources. The TextView ends up added to an array of views inside the LinearLayout, check the source!
👍 1
t

The Monster

08/12/2021, 1:51 PM
I found it in ViewGroup source code at the location specified. It's my first time asking question here, so I guess I used the channel incorrectly. Still, thanks for the help.
h

Haomin

08/13/2021, 9:18 PM
@Luis Thats a great website, I never there is a site like this
👍 1
7 Views