1. Layout
The interior of the layout, in addition to placing the controls, can also be placed in the layout, through the nesting of multiple layers of layout, we can do some more complex interface implementation
Four basic layouts of ¨
Linearlayoutrelativelayoutframelayouttablelayout 2. Supplementary knowledgeView The base class for all user interaction components (widgets) A View object occupies a rectangular area and is responsible for pixel drawing and event handling within the area. ViewGroup Inheriting from the view class ViewGroup class is the base class for all layouts (layouts), and layout classes are not visible for accommodating other view class objects and defining their layout properties. There are two ways to define a layout: 1.working with XML files XML layout file Save in Directory res/layout the extension must be XML, the file name must be lowercase ADT will generate a variable of R class for each XML layout file, for example: Main.xml-->r.layout.main key api:setc Ontentview () Use the advantages of XML to separate the interface of the application from the logical behavior of the application. You can modify and tweak the program interface without having to modify and recompile the source code. Layout parameters How XML layouts are named: layout_something For example: Layout_width defines the width of the component. The layout parameters of the component are used to tell the layout of this component how the component wants to be laid out. 2. Writing using Java code (instantiate layout elements at runtime)
LinearLayout
A linear layout arranges all its subcomponents into one column or row. The default arrangement direction is horizontal (horizontal). Layout parameters ¨android:layout_gravity controls in a horizontal linear layout, Android:layout_ The Gravity property only functions vertically in the vertical direction of the control in a linear layout, and the Android:layout_gravity property only works horizontally ¨android:layout_weight indicates that the component of the linear layout requires additional space to occupy. 0 indicates that the component should be compressed. Otherwise, the component allocates additional space proportionally in the properties greater than 0 components.
android:orientation= "Horizontal"
Relativelayout The child element within the container is determined by its relative to theOther child elementsOrContainerPosition to determine.
Android:layout_alignparentleft,
Android:layout_alignparenttop,
Android:layout_alignparentright,
Android:layout_alignparentbottom,
Android:layout_centerinparent
Framelayout
Framelayout is much simpler than the previous two layouts, so it has a lot less application scenarios. This layout does not have any positioning, and all controls are placed in the upper-left corner of the layout.
Tablelayout
Custom controls
Method One Create a new layout title.xml use <include> tag reference title.xml in the active layout (only show effect, no behavior) Method Two Create a LinearLayout subclass Titlelayout and use Title.xml as a layout to refer to Titlelayout in the active layout (both display and behavior)¨listviewSimple usage of the ListView customizing the ListView's Interface The Click event of the ListView enhances the running efficiency of the ListView ListView is the most commonly used control in Android. Use the ListView when you need to display the list, for example: Phone contacts, chat information, view Weibo information, etc. use: N Use the ListView to display a set of strings
//activity_main.xml<listview android:id= "@+id/list_view" and Roid:layout_width= "Match_parent" android:layout_height= "match_parent" ></listview>//using arrays of type string//Call a Rrayadapter constructor to wrap the data public class Mainactivity extends Activity {private string[] data = {"Apple", "Banana", "Or Ange "," Watermelon "," Pear "," Grape "," Pineapple "," Strawberry "," Cherry "," Mango "}; @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main); arrayadapter<string> adapter = new arrayadapter<string> ( Mainactivity.this, Android. R.layout.simple_list_item_1, data); ListView ListView = (ListView) Findviewbyid (R.id.list_view); Listview.setadapter (adapter); } }
Arrayadapter (context context, int resource, t[] objects) ¨context: A context object that is typically passed into the activity object ¨resource: A layout that contains TextView, A system-provided layout resource is typically used ¨objects: an array of data that, if the data type of the array is not a string, calls the ToString method of the class adapter the Chinese name adapter, which is used to provide ¨ data ¨ layout resources to the ListView
Improve the efficiency of the ListView
The Ngetview method has a Convertview parameter that can directly take advantage of previously loaded layouts to improve code efficiency
ANDROID05-UI02 layout, custom control, ListView