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 7954521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:27:12+00:00 2026-06-04T03:27:12+00:00

I have following problem: in my layout xml I have relative layout in which

  • 0

I have following problem:
in my layout xml I have relative layout in which is placed an ImageView(drawable from app /res folder, is drawn).

I need to add programmatically another ImageView(with another drawable from app resources) exactly on the same place as the initial one and to perform an animation on it.

I almost succeed ,a add new ImageView with new drawable and the layout params taken from the inital ImageView, and perform the animation on it,but the initial ImageView(which is bellow the newly added) is getting smaller – resize itself without reason(the other childs are OK).

How to prevent this?the both images are exactly the same width and height and I need to remain the same…
Thanks in advance.

P.S. update the question .

> <RelativeLayout> .... ... ... <ImageView deck1 > centerverticaly and
> leftof(other UI component) - this is the initial imageview and
> represents deck full of cards.... ... <ImageView deck2>
> centerverticaly and rightof(other UI component) - this is the second
> deck where the cards should be opened.... ... </RelativeLayout>

now I need to take a single card from deck1 and using animation to place it on deck2.
so I do the following:

if(animatingView==null){
ImageView animatingview = new ImageView(this.context);
animatingView.setImageBitmap(R.drawable.backofthecard);
animatinView.setLayoutParams(deck1.getLayoutParams);
RelativeLayout.add(animatingView);
}else{
animatingView.setVisible(visible);
}
animatingView.startAnimation(deckTranslateAnimation);

.
.
..
OnAnimationEnd{animatingView.setVisible(invisible)}

all of the drawables are equal(width and height),so I expect that there won’t be any problems ,but when the animatingView is added to a Layout – deck1 get smaller,resize itself,it is still clickable and displayed but is smaller(and because it gets smaller all the other childs that depend on it,change their places…)

Sorry I didn’t use the real code and xml,but right now I am not in front of them…

Edit:Solved.Here is the code:

if(animatingView==null){
                animatingView = new ImageView(context);
                animatingView.setImageResource(R.drawable.back);
                RelativeLayout.LayoutParams params = new LayoutParams(animatingView.getDrawable().getMinimumWidth(), animatingView.getDrawable().getMinimumHeight());
                params.addRule(RelativeLayout.ALIGN_LEFT, this.getDeckView().getCardView().getId());
                params.addRule(RelativeLayout.ALIGN_TOP, this.getDeckView().getCardView().getId());
                animatingView.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-04T03:27:14+00:00Added an answer on June 4, 2026 at 3:27 am

    Can you show the code you are using?
    Anyway, i think it is better to use FrameLayout to show views that may overlapped to each other. My first thought without seeing the code is to wrap the existing ImageView with FrameLayout. Then when you want to programmatically add new ImageView, you can do it by adding it as FrameLayout’s child. FrameLayout renders view in different layer, so the old one should not be affected when you do something with the newly added view.

    [updated]

    I just tried to implement placing imageview over another imageview. Anyway, I don’t seem to get the problem on the size of the overlapped image. Here are my implementation. Please try this and see if it worked or not. You may have to change some variables though.

    .java

    import android.app.Activity;
    import android.content.Context;
    import android.os.Bundle;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.view.animation.Animation;
    import android.view.animation.Animation.AnimationListener;
    import android.view.animation.AnimationUtils;
    import android.widget.Button;
    import android.widget.ImageView;
    import android.widget.RelativeLayout;
    
    public class ImageStackActivity extends Activity {
    
        Context context;
        RelativeLayout relativeLayout;
        ImageView deck1;
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            context = this.getApplicationContext();
            deck1 = (ImageView)findViewById(R.id.deck1);
            Button button = (Button)findViewById(R.id.button);
            Button button2 = (Button)findViewById(R.id.button2);
            relativeLayout = (RelativeLayout)findViewById(R.id.relative_layout);
    
            button.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    ImageView img = new ImageView(context);
                    img.setBackgroundResource(R.drawable.photo3);
                    img.setLayoutParams(deck1.getLayoutParams());
                    relativeLayout.addView(img);
                    Animation anim = AnimationUtils.loadAnimation(context, android.R.anim.fade_in);
                    img.startAnimation(anim);
                }
            });
            button2.setOnClickListener(new OnClickListener() {          
                @Override
                public void onClick(View v) {
                    if(relativeLayout.getChildCount()>2){
                        relativeLayout.removeViewAt(2);
                    }
                }
            });
        }
    }
    

    main.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >
    
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/relative_layout"
        >
        <ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" 
          android:id="@+id/deck1"
          android:src="@drawable/photo2"
        />
        <ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" 
          android:id="@+id/deck2"
          android:src="@drawable/photo3"
          android:layout_toRightOf="@id/deck1"
        />
    </RelativeLayout>
    <Button 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:id="@+id/button"
        android:text="add image"
        />
    <Button 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:id="@+id/button2"
        android:text="clear"
        />
    </LinearLayout>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following menu layout in my Android app: <?xml version=1.0 encoding=utf-8?> <menu
I have the following layout for my ImageView : <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android
I have the following layout: <?xml version=1.0 encoding=utf-8?> <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent android:layout_height=fill_parent> <GridView android:id=@+id/grid
I have the following layout buttons.xml <?xml version=1.0 encoding=UTF-8?> <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:id=@+id/buttonsLayout android:layout_width=fill_parent android:layout_height=wrap_content
The scenario is the following: I have an activity RunTrainingWorkoutsView that uses XML layout
hi i have the following xml layout <Button android:id=@+id/signupButton android:layout_gravity=left android:layout_width=100sp android:layout_height=wrap_content android:layout_marginLeft =
I'm having the following problem: I have a ListView and I get the layout
I have the following xml for an edittext and button which take the whole
I have the following problem: I want to add a custom view (custom_view.xml and
I have the following basic layout <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:orientation=vertical android:layout_width=fill_parent android:layout_height=fill_parent> <LinearLayout android:orientation=horizontal android:layout_width=fill_parent

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.