当前位置:网站首页>Ndroid development from introduction to mastery Chapter 2: view and ViewGroup

Ndroid development from introduction to mastery Chapter 2: view and ViewGroup

2022-06-26 17:03:00 Yu Yue

Android Development from entry to mastery

Chapter II : View And ViewGroup

UI Overview

View And ViewGroup The concept of

stay Android APP in , All user interface elements are composed of View and ViewGroup The object of .View Is an object that users drawn on the screen can interact with . and ViewGroup It is used to store other View( and ViewGroup) Object's layout container ! Android It provides us with a View and ViewGroup Set of subclasses , Collection provides some common input controls ( Such as buttons and text fields ) And all kinds of layout patterns ( Such as linear or relative layout

User Interface Layout

APP Every component on the user interface of the is using View and ViewGroup Object hierarchy , Every ViewGroup It's all about organizing the invisible View The container of , And its son View It could be an input control Or in UI A widget that draws an area on the . With a hierarchical tree , You can do it according to your own needs , Simple or complex design Miscellaneous layout ( The simpler the layout, the better the performance )

UerInterfaceLayout
Define your layout , You can instantiate... In code View Object and start building your tree , But the easiest and most efficient way to define your layout is to use a XML file , use XML To form a layout more in line with people's reading habits , and XML Similar to HTML Use XML The name of the element represents a View. therefore < TextView > Element will create a... In your interface TextView Control , And one < LinearLayout > I'm going to create one LinearLayout The container of ! for instance , A simple vertical layout with a text view and a button , It looks like this :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent" 
              android:layout_height="fill_parent"
              android:orientation="vertical" >
    <TextView android:id="@+id/text"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="I am a TextView" />
    <Button android:id="@+id/button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="I am a Button" />
</LinearLayout>

User Interface Components

Of course , When landing for actual combat , You don't need to use it all View and ViewGroup Object to create UI Layout .Android It gives us some app Control , The standard UI Layout , You just need to define the content . these UI Components have their properties introduced API file , Such as operation bar , Dialog box, status notification bar, etc .

Blogger GitHub Address

https://github.com/yuyue5945

Pay attention to the official account

20220216225203

原网站

版权声明
本文为[Yu Yue]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202162259261539.html