<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="游泳" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="读书" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="男" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="女" />
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<SeekBar
android:id="@+id/id_seek_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="200"
android:maxHeight="100dp"
android:maxWidth="100dp"
android:progress="50"/>
<TextView
android:id="@+id/tv_value_seekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="0"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ProgressBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/Base.TextAppearance.AppCompat.Large"/>
<ProgressBar
android:id="@+id/probar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/Base.Widget.AppCompat.ProgressBar.Horizontal"
android:progress="30"
android:max="200"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/btn_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="增加"/>
<Button
android:id="@+id/btn_reduce"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="减少"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<DatePicker
android:id="@+id/dp_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:theme="@android:style/Theme"
>
</DatePicker>
<TimePicker
android:id="@+id/tp_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:theme="@android:style/Theme">
</TimePicker>
</LinearLayout>
</LinearLayout>
java
package com.example;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.ProgressBar;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.TimePicker;
import org.w3c.dom.Text;
public class MainActivity extends AppCompatActivity {
SeekBar seekBar;
TextView textView;
ProgressBar progressBar;
DatePicker datePicker;
TimePicker timePicker;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
seekBar = (SeekBar) findViewById(R.id.id_seek_bar);
textView = findViewById(R.id.tv_value_seekbar);
progressBar = findViewById(R.id.probar);
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
textView.setText(String.valueOf(progress));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
findViewById(R.id.btn_add).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
progressBar.setProgress(progressBar.getProgress() + 5);
}
});
findViewById(R.id.btn_reduce).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
progressBar.setProgress(progressBar.getProgress() - 5);
}
});
datePicker = (DatePicker) findViewById(R.id.dp_id);
Log.e("tag", "年份:" + datePicker.getYear());
Log.e("tag", "月份:" + datePicker.getMonth());
Log.e("tag", "日期:" + datePicker.getDayOfMonth());
timePicker = findViewById(R.id.tp_id);
Log.e("tag", "时数:"+timePicker.getHour());
Log.e("tag", "分钟数:"+timePicker.getMinute());
}
}