3. Basic controls


        Controls, good concept, not much to say. There are many controls that come with Android (included and integrated), and some commonly used ones are: TextView (text display, hello in the previous section, world), Button (button, not much to say), ImageView (picture, display a picture) , icon), EditText (edit box, pop-up input method to input text), LinerLayout (linear layout), RelativeLayout (relative layout). The layout can also be said to be a control, which usually contains some subclass controls to manage the positional relationship of the subclasses.


Android controls generally include:

1. Some attributes (in xml):
        (1) android:id (a sign of the index control in the code), @+id/tv_review, R.id.tv_review (an integer value can be used in the code) , the development tools will be automatically generated).
        (2) android:layout_width (width), xdp (how much dp is fixed), wrap_content (contains content), match_parent (full parent class).
        (3) android:layout_height (height), xdp (how much dp is fixed), wrap_content (including content), match_parent (full of parent classes).
        (4) android:padding (the distance from its own content to its own border), xdp (how much dp is fixed).
        (5) android:layout_margin (the distance from its own border to the parent class (usually layout)), xdp (how much dp is fixed).

The above are the properties that most Android controls have, and different controls also have their own unique properties.


2. Some methods (what?):
        There are many, such as: getText(), setText(), which will be used below, let’s talk about it.
3, some events (what?):
        such as: click (onClick) and so on.


1. TextView
        displays a line (a paragraph) of text, such as hello, world. Its attribute android:text is the text to be displayed, android:textColor is the font color, android:textSize font size, etc. There are many attributes that can be mastered slowly.

Second, the Button
        button is the button. Its attribute android:text is the text on the button, android:textColor is the font color, android:textSize font size and so on.

Third, the ImageView
        displays the image container. Its attribute android:src is the picture to be displayed, etc.

Fourth, EditText
        edit box (input box), accept user input method input. android:text is the input content, etc.

5. LinerLayout
        linear layout, android:orientation sets the direction, vertical vertical, the subclasses contained in it are arranged vertically downward, horizontal horizontal, the subclasses contained in it are arranged horizontally to the right.

6. RelativeLayout
        relative layout, in which the subclass can specify the relative position relationship, android:layout_alignParentLeft, when the value is set to true, the subclass is located on the left side of the parent class, and similarly android:layout_alignParentRight is located on the right side of the parent class. Wait, slowly understand.

        Using the most basic controls and layouts above, build a small page for user responses:


        最上方一个TextView,显示用户的评论,下方一个EditView,用户输入,再下方,左侧一个表情的图标(ImageView),右侧回复按钮(Button)。当用户点击回复按钮(Button)时,将输入的内容(EditText)显示到上方的TextView中。

一、界面

        分析,共包含三块区域,成纵向排列,可以用LinerLayout,最下方一个靠左,一个靠右,可以用RelativeLayout(作为子类包含在LinerLayout)。修改xml如下:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#f3f3f3" >

    <LinearLayout
	  android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_margin="6dp"
          android:orientation="vertical"
          android:background="#ffffff">
        
    	  <TextView
                android:id="@+id/tv_review"
        	android:layout_width="match_parent"
        	android:layout_height="wrap_content"
        	android:layout_margin="12dp"
        	android:text="暂无回复"
        	android:textSize="14sp" />
    	  <View
	  	android:layout_width="match_parent"
        	android:layout_height="6dp"
        	android:background="#f3f3f3" />
    	  <EditText
                android:id="@+id/et_review"
	  	android:layout_width="match_parent"
        	android:layout_height="60dp"
        	android:layout_marginTop="12dp"
        	android:layout_marginLeft="12dp"
        	android:layout_marginRight="12dp"
        	android:textSize="14sp"
        	android:background="#e0e0e0"/>
    	  <RelativeLayout
        	android:layout_width="match_parent"
        	android:layout_height="wrap_content"
        	android:layout_marginLeft="12dp"
        	android:layout_marginRight="12dp"
        	android:layout_marginTop="6dp"
        	android:layout_marginBottom="12dp">
        
        	<ImageView 
                    android:layout_width="30dp"
        	    android:layout_height="30dp"
           	    android:src="@drawable/ic_launcher"/>
        	<Button
                    android:id="@+id/bt_review"
		    android:layout_width="70dp"
        	    android:layout_height="30dp"
       	            android:layout_alignParentRight="true"
        	    android:text="回复"
        	    android:textSize="14sp"
        	    android:background="#0088ff"/>
        </RelativeLayout>
    </LinearLayout>
</RelativeLayout>

二、功能

下节实现。


坚持不懈——2016/10/19


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326298318&siteId=291194637