Android——Basic Controls (10)

1. Image view: ImageView

1.1 Knowledge points

(1) Master the use of ImageView components;

(2) Master the preservation of pictures;

1.2 Specific details

We have said before that RadioGroup provides a container for storing RadioButtons, and ImageView also provides a container for placing pictures. In the android project, all pictures are saved in the res/drawable folder.

We all know that after placing the image in the drawable folder, it will be registered in the R.java file and an ID will be generated.

 

  <ImageView
        android:id="@+id/img1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/psb"/>
    <ImageView
        android:id="@+id/img1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/psb"/>
	 <ImageView
        android:id="@+id/img2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/abc"/>

1.3 Summary

All images are required to be saved in the drawable-xx folder;

2. Image button: ImageButton

2.1 Knowledge points

(1) Master the use of ImageButton;

2.2 Specific details

Regarding the definition of ImageButton, you can find that it is a special image view. Like Button, it is a special text display component. ImageButton is a subclass of ImageView, which means that it extends the functions of the image view, and all the functions in ImageView Definitions can be used in ImageButton.

<ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher" />

 2.3 Summary

ImageButton can set the style of the button in the form of a picture.

3. Time picker: TimePicker

3.1 Knowledge points

(1) Master the use of time selector;

(2) The displayed time can be configured through the program;

3.2 Specific details

Example: Use time picker to select time

<TimePicker
        android:id="@+id/tp1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

 This kind of time picker has different display effects in different language environments, which means that this component is an international component. By default, the time is in 12-hour format, but we can set it to 24-hour format through the program.

public class TimePickerActivity extends Activity {
	private TimePicker tp1 = null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_time_picker);
        this.tp1 = (TimePicker) super.findViewById(R.id.tp1);
        this.tp1.setIs24HourView(true);//设置为24小时
        this.tp1.setCurrentHour(18);//设置小时
        this.tp1.setCurrentMinute(20);//设置分钟
        this.tp1.setEnabled(false);//设置不能调整
    }

3.3 Summary

The time selector can directly adjust the time display;

4. Date Picker: DatePicker

4.1 Knowledge points

(1) Master the configuration and use of date picker.

4.2 Specific details

<DatePicker
        android:id="@+id/dp1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

 

This date picker displays the year, month and day. If it is in other locales, the displayed content will be different. It is also an international component. The above program only displays the current date. We can also set the displayed date. 

public class DatePickerActivity extends Activity {
	private DatePicker dp1 = null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.setContentView(R.layout.activity_date_picker);
        this.dp1 = (DatePicker) super.findViewById(R.id.dp1);
        this.dp1.setEnabled(false);//设置不可编辑
        this.dp1.updateDate(2008, 7, 8);//设置显示的时间 在Java中,月是从0-11的。
    }
}

4.3 Summary

(1) The date selector can configure the date;

(2) Different display style configurations can be configured through settings.

Guess you like

Origin blog.csdn.net/weixin_41830242/article/details/131240137