Answer the question
In order to leave comments, you need to log in
Positioning in Android?
Hello Comrades, I need your help! Here is my .xml code
<?xml version="1.0" encoding="utf-8"?>
<!--Normal Screen-->
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/Relative"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/imageViewBg"/>
<ru.xmarkt.flashlight.button.VerticalSeekBar
android:layout_width="wrap_content"
android:layout_height="145dp"
android:layout_x="150dp"
android:layout_y="200dp"
android:id="@+id/vertical_Seekbar"
android:layout_centerHorizontal="true"
android:thumb="@drawable/button_normal"
android:progressDrawable="@drawable/style_seekbar"
android:layout_marginBottom="65dp"
android:layout_above="@+id/adView"
android:thumbOffset="12dp" />
</RelativeLayout>
**
* Created by MasterCoder on 30.10.2015.
* Класс реализующий вертикальный бар в виде кнопки.
*/
public class VerticalSeekBar extends SeekBar {
public VerticalSeekBar(Context context) {
super(context);
}
public VerticalSeekBar(Context context, AttributeSet attributeSet, int defStyle) {
super(context, attributeSet, 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 canvas) {
canvas.rotate(-90);
canvas.translate(-getHeight(),0);
super.onDraw(canvas);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (!isEnabled()) {
return false;
}
switch (event.getAction()) {
case MotionEvent.ACTION_MOVE:
setProgress(getMax() - (int) (getMax() * event.getY() / getHeight()));
onSizeChanged(getWidth(), getHeight(), 0, 0);
break;
case MotionEvent.ACTION_UP:
if(getProgress() >= getMax()/2){
setProgress(getMax());
onSizeChanged(getWidth(), getHeight(), 0, getHeight());
}
else{
setProgress(0);
onSizeChanged(getWidth(), 0, 0, getHeight());
}
break;
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_CANCEL:
break;
}
return true;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question