我有兩個SeekBar
在我看來,我的佈局類似聲明它們:Android的 - 搜索欄的起點
<SeekBar android:id="@+id/select_price"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp" />
<TextView android:id="@+id/max_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0 VND"
android:layout_gravity="center" />
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="horizontal">
<ImageView android:layout_width="20dp"
android:layout_height="20dp"
android:src="@drawable/ic_distance"
android:layout_marginRight="5dp" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text="@string/max_distance" />
</LinearLayout>
<SeekBar android:id="@+id/select_distance"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"/>
<TextView android:id="@+id/distance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0 Km"
android:layout_gravity="center" />
這裏是我使用他們的代碼:
SeekBar sb = (SeekBar) v.findViewById(R.id.select_price);
sb.setMax(1000);
sb.setProgress(10);
sb.setOnSeekBarChangeListener(new OnSeekBarChangeListener(){
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
TextView text = (TextView) v.findViewById(R.id.max_price);
text.setText(Integer.toString(progress) + PlaceListActivity.this.getResources().getString(R.string.dong));
maxPrice = progress;
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
});
SeekBar seek = (SeekBar) v.findViewById(R.id.select_distance);
seek.setMax(10);
seek.setProgress(1);
seek.setOnSeekBarChangeListener(new OnSeekBarChangeListener(){
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
TextView text = (TextView) v.findViewById(R.id.distance);
text.setText(Integer.toString(progress) + PlaceListActivity.this.getResources().getString(R.string.km));
maxDistance = progress;
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
});
但是,當我調試應用程序在我的設備,第一個搜索條是好的,但在另一個會很奇怪,我不要」不知道爲什麼。這是截圖:
正如你所看到的,在第一欄的出發點不是從一開始。這可能是什麼原因?我真的希望有人能幫我解決這個問題。謝謝。
感謝您使用所有解釋和代碼清楚地說明問題! –