AnalogClock、ToggleButton、Switch、RatingBar、SeekBar
2015-04-14 18:20
489 查看
activity_main.xml
MainActivity.java
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:padding="10dp" > <ScrollView android:layout_width="match_parent" android:layout_height="match_parent" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <AnalogClock android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="选择开关:" /> <ToggleButton android:id="@+id/togglebutton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked="false" android:textOff="关闭" android:textOn="开启" /> <Switch android:id="@+id/sw" android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked="true" android:textOff="关闭" android:textOn="开启" /> <TextView android:id="@+id/textts" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@android:color/background_dark" android:textSize="20sp" /> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#000000" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="20dp" android:text="打分" /> <RatingBar android:id="@+id/ratingbar" android:layout_width="wrap_content" android:layout_height="wrap_content" android:max="6" android:numStars="6" android:progress="2" android:stepSize="0.5" /> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#000000" /> <TextView android:id="@+id/textrb" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <ImageView android:id="@+id/img" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:src="@drawable/ic_launcher" /> <SeekBar android:id="@+id/seekbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:max="255" android:progress="255" /> <TextView android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" /> </LinearLayout> </ScrollView> </LinearLayout>
MainActivity.java
import android.app.Activity; import android.os.Bundle; import android.text.method.ScrollingMovementMethod; import android.widget.CompoundButton; import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.ImageView; import android.widget.RatingBar; import android.widget.RatingBar.OnRatingBarChangeListener; import android.widget.SeekBar; import android.widget.SeekBar.OnSeekBarChangeListener; import android.widget.Switch; import android.widget.TabHost.OnTabChangeListener; import android.widget.TextView; import android.widget.ToggleButton; public class MainActivity extends Activity { private ImageView img; private SeekBar seekbar; private TextView text; private RatingBar ratingbar; private TextView textratingbar; private ToggleButton togglebutton; private Switch sw; private TextView textts; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); img=(ImageView)findViewById(R.id.img); seekbar=(SeekBar)findViewById(R.id.seekbar); text=(TextView)findViewById(R.id.text); //text可以滚动 text.setMovementMethod(ScrollingMovementMethod.getInstance()); seekbar.setOnSeekBarChangeListener(new MyOnSeekBarChange()); //SeekBar拖动条事件结束 //SeekBar评分开始 ratingbar=(RatingBar)findViewById(R.id.ratingbar); textratingbar=(TextView)findViewById(R.id.textrb); ratingbar.setOnRatingBarChangeListener(new MyOnRatingBarChang()); //状态开关 togglebutton=(ToggleButton)findViewById(R.id.togglebutton); sw=(Switch)findViewById(R.id.sw); textts=(TextView)findViewById(R.id.textts); togglebutton.setOnCheckedChangeListener(new MyOnCheckedChangeListener()); sw.setOnCheckedChangeListener(new MyOnCheckedChangeListener()); } /** * SeekBar拖动条事件 * @author Administrator * */ private class MyOnSeekBarChange implements OnSeekBarChangeListener{ @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { // TODO Auto-generated method stub text.append("显示中:"+seekBar.getProgress()+"\n"); //设置透明度 img.setImageAlpha(progress); } @Override public void onStartTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub text.append("开始"+"\n"); } @Override public void onStopTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub text.append("结束"+"\n"); } } /** * SeekBar评分 * @author Administrator * */ private class MyOnRatingBarChang implements OnRatingBarChangeListener{ @Override public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) { // TODO Auto-generated method stub textratingbar.setText("用户评分:"+rating); } } /** * ToggleButton Switch状态开关 * @author Administrator * */ private class MyOnCheckedChangeListener implements OnCheckedChangeListener{ @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { textts.setText("您的选择是:开"); }else { textts.setText("您的选择是:关"); } } } }
相关文章推荐
- 常用控件Toggle-Switch-SeekBar-RatingBar
- Android开发-ToggleButton-Switch-RatingBar-AndroidStudio
- Android开发-ToggleButton-Switch-RatingBar-AndroidStudio
- ImageView、设定拓展硬件权限(读取内存卡)、ToggleButton、Switch、RatingBar、SeekBar
- 常用控件(ProgressBar,Toggle,Switch,SeekBar,RatingBar)解析
- Android中ToggleButton,Switch,SeekBar,RatingBar的一些用法
- Android基础控件ToggleButton→ Switch→ SeekBar→ProgressBar 控件
- Android—ToggleButton、Switch和RatingBar使用
- ToggleButton,Switch,RatingBar的使用
- Android学习之RatingBar,SeekBar,ToggleButton,Switch
- RatingBar,SeekBar,ToggleButton的一些属性及其方法
- marsAndroid学习——SeekBar和RatingBar控件
- SeekBar和RatingBar
- android学习---SeekBar和RatingBar
- Android UI基础——SeekBar&RatingBar控件
- 安卓控件 seekbar 和 RatingBar
- ToggleButton和Switch
- SeekBar和RatingBar
- android------(自动调节的进度条+评级测试)SeekBar和RatingBar
- (六)ImageView及其使用 SeekBar及其使用 RatingBar及其使用 ProcessingBar及其使用