我在相对布局中为自定义列表视图创建了一个垂直搜索栏。在相对布局下,我有另一个带有其他文本视图的线性布局。整个布局是片段。我的问题是垂直搜索栏没有像我预期的那样出现。我已经为搜索栏提供了 270 的旋转。请给一些建议。抱歉,我没有发布图片的声誉。
提前致谢。
public class VerticalSeekBar extends SeekBar {
public VerticalSeekBar(Context context) {
super(context);
}
public VerticalSeekBar(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public VerticalSeekBar(Context context, AttributeSet attrs) {
super(context, attrs);
}
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(h, w, oldh, oldw);
}
@Override
protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(heightMeasureSpec, widthMeasureSpec);
setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth());
}
protected void onDraw(Canvas c) {
c.rotate(-90);
c.translate(-getHeight(),0);
super.onDraw(c);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (!isEnabled()) {
return false;
}
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_MOVE:
case MotionEvent.ACTION_UP:
int i=0;
i=getMax() - (int) (getMax() * event.getY() / getHeight());
setProgress(i);
Log.i("Progress",getProgress()+"");
onSizeChanged(getWidth(), getHeight(), 0, 0);
break;
case MotionEvent.ACTION_CANCEL:
break;
}
return true;
}
}
在你的布局中使用这个
<youpackagename.VerticalSeekBar
android:id="@+id/seek"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:progressDrawable="@drawable/seekbar_bg"
android:thumb="@drawable/seekbar_control" />
seekbar_bg.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@android:id/background">
<shape>
<corners android:radius="5dip" />
<gradient
android:angle="270"
android:centerColor="#0F0F0F"
android:centerY="0.75"
android:endColor="#000000"
android:startColor="#000000" />
</shape>
<stroke android:width="2dp" android:color="#0F0F0F"/>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="5dip" />
<gradient
android:angle="270"
android:centerColor="#22e4fa"
android:centerY="0.75"
android:endColor="#01a5db"
android:startColor="#0294d5" />
</shape>
</clip>
</item>
</layer-list>