垂直搜索栏与片段视图中的listview

时间:2013-11-14 12:32:48

标签: android fragment seekbar

我在相对布局中创建了一个垂直搜索栏右边的自定义列表视图。在相对布局中,我有另一个线性布局和一些其他文本视图。 整个布局都是碎片。 我的问题是垂直搜索栏没有像我预期的那样出现。我已经为搜索栏提供了270的轮换。请提出一些建议。 抱歉,我没有声望发布图片。

先谢谢。

1 个答案:

答案 0 :(得分:0)

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>