Android(安卓)之 SeekBar用法介绍
16lz
2021-12-04
拖动条:
布局文件:
主程序入口:
布局文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/gridView" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <EditText android:id="@+id/font" android:layout_width="match_parent" android:layout_height="300dp" android:ems="10" android:lines="5" android:text="看我大小,别翻眼..." android:inputType="textMultiLine" > <requestFocus /> </EditText> <SeekBar android:id="@+id/seekBar" android:layout_width="fill_parent" android:layout_height="wrap_content" android:max="100" android:scrollbarStyle="insideOverlay" android:progress="1" /></LinearLayout>
主程序入口:
package com.example.advancedview;import android.app.Activity;import android.os.Bundle;import android.widget.EditText;import android.widget.SeekBar;import android.widget.Toast;import android.widget.SeekBar.OnSeekBarChangeListener;/** * SeekBar 功能演示, 拖动来改变字体的大小 * @author Administrator * */public class SeekBarActivity extends Activity {//声明变量private SeekBar seekBar;private EditText font;protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.seek_bar_layout);font = (EditText) findViewById(R.id.font);seekBar = (SeekBar) findViewById(R.id.seekBar);seekBar.setOnSeekBarChangeListener(seekListerner);}// 拖动条事件private OnSeekBarChangeListener seekListerner = new OnSeekBarChangeListener() {// 拖动条停止执行public void onStopTrackingTouch(SeekBar seekBar) {Toast.makeText(SeekBarActivity.this, "停止了:"+seekBar.getProgress(), 1000).show();}// 开始执行public void onStartTrackingTouch(SeekBar seekBar) {Toast.makeText(SeekBarActivity.this, "开始了:"+seekBar.getProgress(), 1000).show();}// 拖动中public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {font.setTextSize(progress); // 改变字体的大小}};}
更多相关文章
- TextView碉堡了!android源代码的一些统计信息!
- Android(安卓)- Android实现定时器的方法
- Android(安卓)原生项目集成 Flutter
- android在布局中图片大小自适应
- Android预定义样式
- Android预定义样式
- android中用Spannable在TextView中设置超链接、颜色、字体
- Android(安卓)Handler简单例子
- android代码片段二