Views

A view is a layout element that occupies a set area of the screen and is responsible for drawing and event handling. View is the base class for UI elements or widgets such as text fields, input fields, and buttons. All views extend the View class.

Views can be created within an XML layout in a source file. Consider the following code:

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Roll the dice!"/>

Besides creating views directly in a layout file, they can also be created programmatically within program files. For example, a text view can be made by creating an instance of the TextView class and passing a context to its constructor. This is demonstrated in the following code snippet:

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val textView: TextView = TextView(this)
}
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.194.106