我正在编写一个应用程序,它看起来像这样:
您如何看到顶部有 SeekBar,下面的 HorizontalScrollView 中有几个按钮。我想使用 SeekBar 来滚动按钮,现在这工作正常,但我无法关闭滚动视图(拖动屏幕)的默认方式。我在论坛上找到了类似的话题:
但问题是,这种方式锁定了整个 ScrollView,我不能通过 seekBar 和默认方式使用它 - 也许我做错了什么(我在链接中做了同样的事情,即使我在 mScrollable 中有 TRUE 这也没有用范围)。第二个问题是我的按钮(具有 fill_parent 高度参数)非常小。
问题:有什么好的方法可以默认锁定滚动视图并使用 SeekBar 来做到这一点?
我的代码(默认 HorizontalScrollView):
public class MainActivity extends Activity implements SeekBar.OnSeekBarChangeListener {
static private String TAG = "MainActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
SeekBar seek = (SeekBar) findViewById(R.id.seekBar);
final HorizontalScrollView hsv = (HorizontalScrollView)findViewById(R.id.hsv);
seek.setMax(948);
seek.setProgress(474);
seek.setOnSeekBarChangeListener(this);
hsv.post(new Runnable() {
@Override
public void run() {
hsv.scrollTo(474, 0);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch) {
HorizontalScrollView hsv = (HorizontalScrollView)findViewById(R.id.hsv);
hsv.scrollTo(progress, 0);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
Log.d(TAG, "Tracking on");
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
Log.d(TAG, "Tracking off");
}
活动主:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#0A0A0A"
android:orientation="vertical" >
<SeekBar
android:id="@+id/seekBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<HorizontalScrollView
android:id="@+id/hsv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbars="none" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<!-- BUTTONS CODE - NOT IMPORTANT -->
</RelativeLayout>
</HorizontalScrollView>
</LinearLayout>