我正在开发一个应用程序,我正在使用seekbar。我的搜索栏有最大值6,即android:max =“6”因为我希望有5个间隔。我的问题是搜索栏没达到最后我尝试了很多东西但仍然无助所以任何人都可以建议我做什么。 我的代码是
public class MainActivity extends Activity implements SeekBar.OnSeekBarChangeListener
{
SeekBar seekBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
seekBar=(SeekBar)findViewById(R.id.seek);
int max = 6;
seekBar.setMax(max);
seekBar.setProgress(0);
seekBar.setOnSeekBarChangeListener(this);
}
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
}
public void onStartTrackingTouch(SeekBar seekBar) {
// Notify that the user has started a touch gesture.
}
public void onStopTrackingTouch(SeekBar seekBar) {
// Notify that the user has finished a touch gesture.
}
}
由于
答案 0 :(得分:1)
XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
>
<SeekBar
android:layout_width="match_parent"
android:layout_height="30dp"
android:max="6"
android:id="@+id/sb"
/>
</LinearLayout>
Activity.java
public class MyActivity extends Activity implements SeekBar.OnSeekBarChangeListener {
private SeekBar sb;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
sb = (SeekBar)findViewById(R.id.sb);
sb.setOnSeekBarChangeListener(this);
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
}
所有的工作都像魅力。希望它有所帮助。
答案 1 :(得分:1)
尝试在搜索栏的末尾添加一些填充:
myseekbar.setPadding(0,0,5,0);