Android development - control EditText, 2. Obtain the data input by EditText, realize by clicking the button, ImageView control, zoom type, control ProgressBar, detailed explanation of common properties, progress bar setting

1. EditText

1. Main attributes

1. android : hint input prompt
2. android : textColorHint  Enter the color of the hint text
3. android : inputType  input type
4. android : drawableXxxx Add a picture in the specified position of the input box
5. android : drawablePadding  Set the distance between the image and the input content
6. android : paddingxxxx  Set the spacing between the content and the border
7. android : background  background color

<EditText
        android:hint="请输入用户名"
        android:textColorHint="#95a1aa"
        android:inputType="phone"
        android:layout_width="200dp"
        android:layout_height="100dp"/>

    <EditText
        android:hint="请输入密码"
        android:textColorHint="#95a1aa"
        android:inputType="textPassword"
        android:layout_width="200dp"
        android:layout_height="100dp"/>

1.1.android : The hint will only be displayed when it is not input, and it will not prompt after input

1.2EditText inherits from TextView, some EditText of TextView can basically be set

 2. Obtain the data entered by EditText and realize it by clicking the button

in Mainactivity.java

        private EditText et;

        Button btn_1 = findViewById(R.id.btn_1);
        et = findViewById(R.id.et);

        btn_1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String text = et.getText().toString();
                Log.e("led", "输入的内容: " +text);
            }
        });

In activity_main.xml, write

    <EditText
        android:hint="请输入密码"
        android:textColorHint="#95a1aa"
        android:inputType="textPassword"
        android:drawableLeft="@drawable/baseline_person_24"
        android:drawablePadding="20dp"
        android:paddingLeft="20dp"
        android:background="@color/white"
        android:layout_width="200dp"
        android:layout_height="100dp"/>

    <Button
        android:id="@+id/btn_1"
        android:text="获取用户名"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

 At this time, after clicking the button, you will see it at the runtime, which is very successful

 Two. ImageView control

1. Main attributes

1. android : src  Set image resource
2. android : scaleType  Set image scaling type
3. android : maxHeight  maximum height
4. android : maxWidth  maximum width
5. android : adjustViewBounds  Adjust the bounds of the View

2. Zoom type

1.fitStart Keep the aspect ratio and scale the picture until the longer side is equal to the side length of the Image, and place the picture in the upper left corner of the ImageView after scaling is complete
2. fitCenter Default value, same as above, put in the middle after scaling
3. fitEnd  Same as above, scaled and placed in the lower right corner
4.fitXY Scale the image vertically and horizontally independently so that the image fits the ImageView completely, but the aspect ratio of the image may change
5. center Keep the size of the original image and display it in the center of the ImageView. When the size of the original image is larger than the size of the ImageView, part of the clipping process is exceeded.
6.centerCrop Keep the aspect ratio and scale the picture until it completely covers the ImageView, and the picture may not be displayed completely
7.centerinstde Scales the image maintaining the aspect ratio until the ImageView can fully display the image
8. matrix

 Do not change the size of the original image, start drawing the original image from the upper left corner of the ImageView, and crop the part of the original image that exceeds the ImageView

maxHeight and maxWidth can only be realized by combining adjustViewBounds
    <ImageView
        android:src="@drawable/ceshi"
        android:scaleType="centerInside"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:maxHeight="200dp"
        android:maxWidth="200dp"
        android:adjustViewBounds="true"
        />

 3. Control ProgressBar

1. Detailed explanation of common attributes

1. android : max : The maximum value of the progress bar
2. android : progress : The progress bar has completed the progress value
3. android : indeterminate : If set to true , the progress bar does not show progress accurately
4.style="? android : attr / progressBarStyleHorizontal " horizontal progress bar

 2. Realize that the click button loading disappears

    <ProgressBar
        android:id="@+id/pb"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

    <Button
        android:text="显示隐藏进度条"
        android:onClick="leoClick"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

In MainActivity.java:

private ProgressBar progressBar;

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        progressBar = findViewById(R.id.pb);

}

  public void leoClick(View view){
      if (progressBar.getVisibility()  == view.GONE) {
          progressBar.setVisibility(View.VISIBLE);
      }else {
          progressBar.setVisibility(View.GONE);
      }
    }

 The functions implemented at this time are as follows:

Disappears when clicked

3. Realize clicking the button and displaying the download progress bar

   <ProgressBar
            android:id="@+id/pb2"
            style="?android:attr/progressBarStyleHorizontal"
            android:max="100"
            android:layout_width="300dp"
            android:layout_height="wrap_content"/>

    <Button
            android:text="模拟下载"
            android:onClick="load"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

In MainActivity.java:

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        progressBar = findViewById(R.id.pb2);

    }
    public void load(View view) {
        int progress = progressBar.getProgress();
        progress += 10;
        progressBar.setProgress(progress);
    }

At this point after the end of the run

You can also make the progress bar not display

Use android:indeterminate="true"

can be achieved

Guess you like

Origin blog.csdn.net/WZY22502701/article/details/129926470