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

  • SEARCH
  • Home
  • 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 8406413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:06:13+00:00 2026-06-09T23:06:13+00:00

I am having a Relative layout with few images in it like this below.

  • 0

I am having a Relative layout with few images in it like this below.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >


    <ImageView
        android:id="@+id/image_2"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_alignLeft="@+id/increase"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="34dp"
        android:layout_marginTop="34dp"
        android:src="@drawable/ic_launcher" />

    <ImageView
        android:id="@+id/image_1"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_alignBottom="@+id/image_2"
        android:layout_marginBottom="14dp"
        android:layout_toRightOf="@+id/increase"
        android:src="@drawable/ic_launcher" />

    <ImageView
        android:id="@+id/image_8"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:src="@drawable/ic_launcher" />
</RelativeLayout>

and in my java file i need to perform a small task.
When i click an image it’s size should be increased.
I tried this and it was working and this is my code

public class MainActivity extends Activity implements OnClickListener {

View imageView;

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

    ImageView i1 = (ImageView ) findViewById(R.id.image_1);
    ImageView i2 = (ImageView ) findViewById(R.id.image_2);
             ImageView i3 = (ImageView ) findViewById(R.id.image_8);
            i1.setOnClickListener(this);
    i2.setOnClickListener(this);
    i3.setOnClickListener(this);
}

public void onClick(View arg0) {
    Log.v("clicked ", "clicked");
    imageView = arg0;
    Toast.makeText(this, "looking to resize the image ", 1).show();
    Toast.makeText(this, "clicked 2", 1).show();

    height = imageView.getHeight();
        width = imageView.getWidth();
    height += 50;
    width += 50;
    imageView.setLayoutParams(new RelativeLayout.LayoutParams(height, width));

}   

}

But i am facing a problem.
when i click the image its position is changing.
Consider these screen shots ..

The below is the screen shot when the application is launched

enter image description here

and below is the screen shot when an image view is clicked.

enter image description here

Can anyone suggest me so that the image doesnt change its position
I can use something like using a grid view (if possible. but even i am trying to put some drag option to it. So can anyone suggest me please)

UPDATED CODE :

the onclick method is updated as below :

public void onClick(View arg0) {
    Log.v("clicked ", "clicked");
    imageView = arg0;
    Toast.makeText(this, "looking to resize the image ", 1).show();
    Toast.makeText(this, "clicked 2", 1).show();

    height = imageView.getHeight();
width = imageView.getWidth();
    height += 50;
    width += 50;
    RelativeLayout.LayoutParams params = new
          RelativeLayout.LayoutParams(height, width);

    params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
    params.setMargins( 
                imageView.getLeft()-30,imageView.getTop()-30,imageView.getRight()+30,
               imageView.getBottom()+30);
    imageView.setLayoutParams(params);



}
  • 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-06-09T23:06:14+00:00Added an answer on June 9, 2026 at 11:06 pm

    You create new layoutparams for a relative layout and only set the height and width. Therefore, the image view will default to top left of the parent relative layout. You also need to set the alignment and margin as you need.

    Since you are using a relative layout, you need to create new RelativeLayout layoutParams:

    http://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html

    Something like this:

    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
    params.setMargins(left, top, right, bottom);
    

    Good luck…

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

Sidebar

Related Questions

I'm having all sorts of problems implementing styles in action bar, i've read http://android-developers.blogspot.com/2011/04/customizing-action-bar.html
Typical search layout having RelativeLayout, TextView, EditText and Button I have a.9.png image having
I am having a problem with views overlapping in a RelativeLayout on Android 1.5...
I have been having problems creating a relative layout in XML for a list
Hello i am having a problem in setting the image in relative layout.The problem
I have been trying to get this layout correct and having trouble. Here is
The code is below but I am having some issues with creating a relative
I am really struggling with this one. Below is an image of a layout
good afternoon How could I get a design like this in my android application?
I am having a very weird exception!. First I reference to a Relative layout,

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.