Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3498970
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:33:16+00:00 2026-05-18T12:33:16+00:00

I’ve been learning Android for about two weeks now (expert in as2/3). I have

  • 0

I’ve been learning Android for about two weeks now (expert in as2/3).

I have created a simple LinearLayout1, which contains anImageView`, containing a png of a vinyl record (just a circular disc basically)

I have set up this ImageView to be rotated when the user drags a finger on it, like scratching a record.

My code seems to be working (not sure if its the best way but it works). The problem is when the ImageView is rotated it pushes other views around. I have determined this is because my round image is really a square with transparent corners. It is these corners that are pushing other views around, and causing the record to push away from the left side of the screen if I have the ImageView left justified.

There are a few attempts to solve this online, but none of them seem to be quite what I need and some are wrapped in examples so robust I can’t discern what to take from it at my beginning level.

If anyone could shed some light on what I can do so solve this that would be great. I realize a simple answer may not exist, but keep in mind I am a Java noob and keep it as simple as you can! Many thanks in advance for any help!

also if anyone can tell me why I need to subtract 50 from the rotation to make the record move under the exact spot the user touches, that would be helpful as well! see this in the method updateRotation().

Here is my xml markup:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
   xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/baseView"
    android:background="#FFFFFFFF"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <ImageView
        android:id="@+id/turntable"
        android:src="@drawable/turntable"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_weight="1"/>

</LinearLayout>

and here is my java code:

package com.codingfiend.android.turntable;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TextView;

public class Turntable extends Activity
{
    View baseView;
    ImageView turntable;
    TextView bottomText;

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.main);

        baseView = (View)findViewById(R.id.baseView);
        turntable = (ImageView)findViewById(R.id.turntable);

        turntable.setOnTouchListener(onTableTouched);
    }

    public android.view.View.OnTouchListener onTableTouched = new android.view.View.OnTouchListener()
    {
        public boolean onTouch(View v, MotionEvent evt)
        {
            double r = Math.atan2(evt.getX() - turntable.getWidth() / 2, turntable.getHeight() / 2 - evt.getY());
            int rotation = (int) Math.toDegrees(r);


            if (evt.getAction() == MotionEvent.ACTION_DOWN)
            {
                //
            }

            if (evt.getAction() == MotionEvent.ACTION_MOVE)
            {
                updateRotation(rotation);
            }

            if (evt.getAction() == MotionEvent.ACTION_UP)
            {
                //
            }

            return true;
        }
    };

    private void updateRotation(double rot)
    {
        float newRot = new Float(rot);

        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.turntable);

        Matrix matrix = new Matrix();
        matrix.postRotate(newRot - 50);

        Bitmap redrawnBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
        turntable.setImageBitmap(redrawnBitmap);
    }
}

EDIT

This is turning out to be an irritating problem. There has got to be a way to rotate an image that is as big or bigger than the screen without it getting scaled so the whole image stays on screen. Why can’t part of the rotating image go off screen? Very frustrating. I tried wrapping the ImageView into a FrameView, which partially helped. Now I can add other views that won’t be affected, but I still can’t have my disc big enough because it isn’t allowed to pass the screen borders when it rotates. I don’t get why. I haven’t checked out extending ImageView yet. Any other thoughts would still be appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T12:33:16+00:00Added an answer on May 18, 2026 at 12:33 pm

    Actually thats because you try to rotate a view in a linear layout. And this will cause its dedicated space to expand or shrink.

    Idea 1: try using a frame layout have and your view rotate inside there
    Idea 2: try a custom view subclass and draw your turntable in the onDraw. In the internet look for a compass drawing example for start.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.