This is the fourth day of my participation in the August More text Challenge. For details, see:August is more challenging
Start by using the Android basic View
In my last post, I talked about the features and benefits of views. Now it’s time to practice writing View code. According to my 4-year working experience, although the system provides a variety of strange views, we only need to learn about a dozen views to cope with most of the needs in actual work.
Today we go straight into practice and get the final results:
Is a page like this a little bit more App like? The page only needs to be written in XML, and it can be previewed in real time in Android Studio, which is also a benefit of the View framework.
The first is a slideable effect, so I’m going to use ScrollView. ScrollView can be landscape or portrait, the default is portrait.
Layout_width and layout_height are attributes that are mandatory for every View and describe the size of the View. They can be wrap_content, match_parent, or fixed values (usually in DP units). Wrap_content stands for the minimum value that can wrap its own content, and match_parent stands for the maximum value within the allowed range. If the value is fixed, the current input value is directly used without calculation.
“Dp” is an Android specific unit of length, which is independent of “screen pixel density”, ensuring that the same VALUE of DP will display the same physical size on different phone screens. Similarly, there is a font dedicated “SP”. By default, the calculation results of the two are the same, but the font size Settings in the mobile phone will affect the calculation results of SP, so the text as far as possible to use SP, but hope not affected by the setting of the text can also use DP.
And then we have a LinearLayout, and the LinearLayout will line up the child views in one direction, which is horizontal by default, so we manually set the orientation to vertical.
Next, we write the View we want in turn. It says that the tag of the View content is itself a TextView. The following View has almost no additional properties set, just follow the label to see how different views look, no more code. (This is a lot of code, so I suggest you go to the github file: activity_base_view_demo.xml)
Let’s take a look at two more static images. The View provided by the system usually has a default style, and it’s part of the Android developer’s daily job to adjust the style as needed.
There are many similarities in the use of View. For example, various views that can display text use Android: Text to set the text content. When you see more, you will subconsciously react.
“
But if you continue to write at this pace, and you draw a body of knowledge, you may have many, many articles, and you become learning all the time, but you can’t write an App. So some of the principles of views and things related to customizing views will take a pause and open up the rest of the page after the previous list of uses for views.
The article in the week time is limited, self feeling content is still too little, everyone has what rich content advice can teach me (perhaps someone to see the words), save the child!