Question: Required Components: ImageView: The image that the buttons will be moving Movement Buttons: Each press should move the ImageView a certain amount, I chose to

Required Components:
ImageView: The image that the buttons will be moving
Movement Buttons: Each press should move the ImageView a certain amount, I chose to move it 50dp per press (you can choose a different amount if you want to)
Up Button: Moves the ImageView towards the top of the screen
Right Button: Moves the ImageView towards the right-hand side of the screen
Down Button: Moves the ImageView towards the bottom of the screen
Left Button: Moves the ImageView towards the left-hand side of the screen
Reset Button: Resets the ImageView back to the center. For the way I implemented it, I set the margins back to 0, which should reset it back to where it started
Additional Requirements
At least one onClick method should be attached in the onCreate method (with an anonymous class or a lambda expression)
The Layout for the buttons and the ImageView is similar to the provided picture
A screenshot image of the completed app, looking similar to the one above. my code so far. activity_main.xml
Mainactivity.java below package com.example.androidtemplate;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
private Button button;
private View imageView;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button resetButton = findViewById(R.id.resetButton);
resetButton.setOnClickListener(view ->{
ViewGroup.MarginLayoutParams marginParams =(ViewGroup.MarginLayoutParams) imageView.getLayoutParams();
marginParams.topMargin =0;
marginParams.bottomMargin =0;
marginParams.leftMargin =0;
marginParams.rightMargin =0;
imageView.setLayoutParams(marginParams);
});
ImageView imageView = findViewById(R.id.imageView);
Button upButton = findViewById(R.id.upButton);
// Similarly, find other buttons
upButton

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!