MainActivity.kt file
When we have created layout, we need to load the XML layout resource from our activity onCreate() callback method and access the UI element form the XML using findViewById.
package com.example.text_view_application
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.EditText
import android.widget.TextView
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.example.text_view_application.ui.theme.Text_View_ApplicationTheme
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContentView(R.layout.activity_main)
val showButton:Button = findViewById(R.id.showInput)
val editText:EditText = findViewById(R.id.editText)
val textView:TextView = findViewById(R.id.txtVw)
}
}
Android LinearLayout in Kotlin
Android LinearLayout is a ViewGroup subclass, used to provide child View elements one by one either in a particular direction either horizontally or vertically based on the orientation property. We can specify the linear layout orientation using the android:orientation attribute.
All the child elements arranged one by one in multiple rows and multiple columns.
- Horizontal list: One row, multiple columns.
- Vertical list: One column, multiple rows.
Can illustrate the Horizontal and Vertical List with an Image.
In this article, we are going to discuss the declaration and implementation of LinearLayout.
Contact Us