W
W
Web_bahdepa2015-11-15 17:40:25
Java
Web_bahdepa, 2015-11-15 17:40:25

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>

do not judge strictly, but the goal is to understand how to position the Vertical SeekBar (to support android 2.3 devices) relative to the background image (ImageView id=imageViewBg ), so that they are located relative to each other in one place depending on the screen resolutions.
Tried various options. But alas, it didn’t work out there are thoughts of ideas on how this can be done. Comrades, I will be glad for any support.
Yes, I will also throw off my SeekBar class:
**
 * 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;
    }

I’m also attaching photos, how I want my application to look like (I didn’t load my images, you’ll see it on Google later):
35858df8b98c43c199234da8dd350e97.jpg
SeekBar uses a button as a thumb, so it turns out a slide button and yes, the height of the bar also needs to be adjusted depending on the background image in order to it was equal to the depression in the center.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question