Class notes: Android UI controls

Common UI controls: TextView: <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" a...
Common UI controls:

Common UI controls:

  • TextView:
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" />

mathch_parent: it means that the current control size can contain exactly the content in it, that is, the space content determines the current space size
android:layout_width: Specifies the width of the control
android:layout_height: Specifies the height of the control
Three optional values:
match_parent,fill_parent: the same size as the parent layout, match is recommended_ parent
warp_content: just the contents of the package
You can also specify a fixed value
The problem is: sometimes there are adaptation problems on different mobile screens
You can use android: gravity to specify how text is aligned

<TextView android:id="@+id/text_view" android:text="tViews" android:gravity="center" android:layout_width="match_parent" android:layout_height="wrap_content" />

Great Xia and color of the revised text

android:textSize : change the size of text in sp

android:textColor : set text size

  • Button
    It is an important button component to interact with users
<Button android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/button_first" android:text="to first"/> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/button_second" android:text="to second"/>

android:textAllCaps="false" to set it

<Button android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/button_first" android:textAllCaps="false" android:text="to first"/>

You can also set up a listener:

public class FirstActivity extends AppCompatActivity { @Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.first_layout); Button first = (Button) findViewById(R.id.button_first); first.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(FirstActivity.this,SecondActivity.class); startActivity(intent); } }); } }

Each click event executes the onClick() method in the listener
You just need to implement your own logic in the listener
At the same time, the interface method can also be implemented to open and register

  • EditText
    Used to interact with users and allow users to enter and edit content into the control
    And can be processed in the program
<EditText android:id="@+id/edit_text" android:hint="Please enter account" android:layout_width="match_parent" android:layout_height="wrap_content" />

android:hint : is the content of the prompt. Click to input the content, and the hi disappears
There is a restriction on the text content you enter
use android:maxLines : value
Limit its maximum row

  • ImageView
    Mainly used to display pictures on the interface
    Can make the program page more colorful
    Note: pictures are usually placed in the directory at the beginning of drawable
android:src: to ImageView Specify a picture <ImageView android:id="@+id/image_view" android:src="@drawable/image" android:layout_width="wrap_content" android:layout_height="wrap_content" />

ProgressBar
Used to display a progress bar on the interface
Indicates that the program loads some data

<ProgressBar android:id="@+id/progress_bar" android:layout_width="match_parent" android:layout_height="wrap_content" /> Progress bar rotation indicates program reloading data //After data loading //Available android:visibility To specify the visibility of the control //Three values: visible (default), invisible, gone //Respectively: visible, invisible, not only invisible but also does not occupy screen space //Click button to switch state //Visible - invisible - visible

26 June 2020, 02:40 | Views: 1109

Add new comment

For adding a comment, please log in
or create account

0 comments