我创建了一个自定义搜索栏,在移动滑块时绘制了一个新的拇指。我现在希望拇指在按下时显示放大的拇指,然后当用户将手指从拇指上移开时显示原始尺寸。如果用户按下拇指,则将其放大到两倍大小。然而,这会导致显示放大的拇指,但搜索栏的其余部分已消失。以下是我的代码:
public class GradeSeekBar extends SeekBar implements OnSeekBarChangeListener {
String TAG = "TOUCHING";
public GradeSeekBar(Context context, SeekBar seekbar) {
super(context);
}
public GradeSeekBar(Context context, AttributeSet attrs) {
super(context, attrs);
}
public GradeSeekBar(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
//
seekBar.setMax(7);
int value = seekBar.getProgress();
switch (value) {
case 0:
final int drawableId1 = R.drawable.readinglevelsliderk;
final Drawable d1 = getResources().getDrawable(drawableId1);
seekBar.setThumb(d1);
break;
case 1: // 1
final int drawableId2 = R.drawable.readinglevelslider1;
final Drawable d2 = getResources().getDrawable(drawableId2);
seekBar.setThumb(d2);
break;
case 2:
final int drawableId3 = R.drawable.readinglevelslider2;
final Drawable d3 = getResources().getDrawable(drawableId3);
seekBar.setThumb(d3);
break;
case 3:
final int drawableId4 = R.drawable.readinglevelslider3;
final Drawable d4 = getResources().getDrawable(drawableId4);
seekBar.setThumb(d4);
break;
case 4:
final int drawableId5 = R.drawable.readinglevelslider4;
final Drawable d5 = getResources().getDrawable(drawableId5);
seekBar.setThumb(d5);
break;
case 5:
final int drawableId6 = R.drawable.readinglevelslider5;
final Drawable d6 = getResources().getDrawable(drawableId6);
seekBar.setThumb(d6);
break;
case 6:
final int drawableId7 = R.drawable.readinglevelslider6;
final Drawable d7 = getResources().getDrawable(drawableId7);
seekBar.setThumb(d7);
break;
case 7: // All
final int drawableId8 = R.drawable.allbutton;
final Drawable d8 = getResources().getDrawable(drawableId8);
seekBar.setThumb(d8);
break;
case 8: // All
final int drawableId9 = R.drawable.allbutton;
final Drawable d9 = getResources().getDrawable(drawableId9);
seekBar.setThumb(d9);
break;
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
int value = seekBar.getProgress();
switch (value) {
case 0:
final int drawableId1 = R.drawable.readinglevelsliderkdouble;
final Drawable d1 = getResources().getDrawable(drawableId1);
seekBar.setThumb(d1);
break;
case 1: // 1
final int drawableId2 = R.drawable.readinglevelslider175x2;
final Drawable d2 = getResources().getDrawable(drawableId2);
seekBar.setThumb(d2);
break;
case 2:
final int drawableId3 = R.drawable.readinglevelslider275x2;
final Drawable d3 = getResources().getDrawable(drawableId3);
seekBar.setThumb(d3);
break;
case 3:
final int drawableId4 = R.drawable.readinglevelslider375x2;
final Drawable d4 = getResources().getDrawable(drawableId4);
seekBar.setThumb(d4);
break;
case 4:
final int drawableId5 = R.drawable.readinglevelslider475x2;
final Drawable d5 = getResources().getDrawable(drawableId5);
seekBar.setThumb(d5);
break;
case 5:
// 5
break;
case 6:
// 6
break;
case 7: // All
break;
case 8: // All
break;
}
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
int value = seekBar.getProgress();
switch (value) {
case 0:
final int drawableId1 = R.drawable.readinglevelsliderk;
final Drawable d1 = getResources().getDrawable(drawableId1);
seekBar.setThumb(d1);
break;
case 1: // 1
final int drawableId2 = R.drawable.readinglevelslider1;
final Drawable d2 = getResources().getDrawable(drawableId2);
seekBar.setThumb(d2);
break;
case 2:
final int drawableId3 = R.drawable.readinglevelslider2;
final Drawable d3 = getResources().getDrawable(drawableId3);
seekBar.setThumb(d3);
break;
case 3:
final int drawableId4 = R.drawable.readinglevelslider3;
final Drawable d4 = getResources().getDrawable(drawableId4);
seekBar.setThumb(d4);
break;
case 4:
final int drawableId5 = R.drawable.readinglevelslider4;
final Drawable d5 = getResources().getDrawable(drawableId5);
seekBar.setThumb(d5);
break;
case 5:
final int drawableId6 = R.drawable.readinglevelslider5;
final Drawable d6 = getResources().getDrawable(drawableId6);
seekBar.setThumb(d6);
break;
case 6:
final int drawableId7 = R.drawable.readinglevelslider6;
final Drawable d7 = getResources().getDrawable(drawableId7);
seekBar.setThumb(d7);
break;
case 7: // All
final int drawableId8 = R.drawable.allbutton;
final Drawable d8 = getResources().getDrawable(drawableId8);
seekBar.setThumb(d8);
break;
case 8: // All
final int drawableId9 = R.drawable.allbutton;
final Drawable d9 = getResources().getDrawable(drawableId9);
seekBar.setThumb(d9);
break;
}
}
}
这是它放在我的main_activity.xml文件中的方式:
<com.android.views.GradeSeekBar
android:id="@+id/seekBar2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imageButtonFilter"
android:layout_toLeftOf="@+id/imageButtonArrowRight"
android:layout_toRightOf="@id/imageButtonFilter"
android:paddingLeft="52dp"
android:paddingRight="35dp"
android:thumb="@drawable/readinglevelsliderk"
android:visibility="visible" />
你可以设置一个特定的最大尺寸吗?