Change View height programmatically Smoothly





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















I am trying to change the height of the view programmatically.

What i have tried is -



RelativeLayout rlOne;
rlOne = (RelativeLayout) findViewById(R.id.rlOne);


And on some click event i am changing the height using the LayoutParams.



rlOne.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, NEWHEIGHT));


The height is increased but the transition is not smooth.

How can i achieve a smooth transition from view's original height to view's new height?

Can i slow down the transition ?










share|improve this question

























  • Why don't you just anmate the transition?

    – g00dy
    Aug 7 '13 at 7:21











  • @MocialovBoris : Can u give me some more inputs on this. Shall i use the scale animation?

    – Anukool
    Aug 7 '13 at 7:32


















1















I am trying to change the height of the view programmatically.

What i have tried is -



RelativeLayout rlOne;
rlOne = (RelativeLayout) findViewById(R.id.rlOne);


And on some click event i am changing the height using the LayoutParams.



rlOne.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, NEWHEIGHT));


The height is increased but the transition is not smooth.

How can i achieve a smooth transition from view's original height to view's new height?

Can i slow down the transition ?










share|improve this question

























  • Why don't you just anmate the transition?

    – g00dy
    Aug 7 '13 at 7:21











  • @MocialovBoris : Can u give me some more inputs on this. Shall i use the scale animation?

    – Anukool
    Aug 7 '13 at 7:32














1












1








1


0






I am trying to change the height of the view programmatically.

What i have tried is -



RelativeLayout rlOne;
rlOne = (RelativeLayout) findViewById(R.id.rlOne);


And on some click event i am changing the height using the LayoutParams.



rlOne.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, NEWHEIGHT));


The height is increased but the transition is not smooth.

How can i achieve a smooth transition from view's original height to view's new height?

Can i slow down the transition ?










share|improve this question
















I am trying to change the height of the view programmatically.

What i have tried is -



RelativeLayout rlOne;
rlOne = (RelativeLayout) findViewById(R.id.rlOne);


And on some click event i am changing the height using the LayoutParams.



rlOne.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, NEWHEIGHT));


The height is increased but the transition is not smooth.

How can i achieve a smooth transition from view's original height to view's new height?

Can i slow down the transition ?







android view height






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 7:09









Cœur

19.3k10116155




19.3k10116155










asked Aug 7 '13 at 7:20









AnukoolAnukool

2,73182236




2,73182236













  • Why don't you just anmate the transition?

    – g00dy
    Aug 7 '13 at 7:21











  • @MocialovBoris : Can u give me some more inputs on this. Shall i use the scale animation?

    – Anukool
    Aug 7 '13 at 7:32



















  • Why don't you just anmate the transition?

    – g00dy
    Aug 7 '13 at 7:21











  • @MocialovBoris : Can u give me some more inputs on this. Shall i use the scale animation?

    – Anukool
    Aug 7 '13 at 7:32

















Why don't you just anmate the transition?

– g00dy
Aug 7 '13 at 7:21





Why don't you just anmate the transition?

– g00dy
Aug 7 '13 at 7:21













@MocialovBoris : Can u give me some more inputs on this. Shall i use the scale animation?

– Anukool
Aug 7 '13 at 7:32





@MocialovBoris : Can u give me some more inputs on this. Shall i use the scale animation?

– Anukool
Aug 7 '13 at 7:32












4 Answers
4






active

oldest

votes


















0














Play with from/to/speed values



ScaleAnimation scaleAnimation = new ScaleAnimation(from, to, from, to, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rlOne.setAnimation(scaleAnimation);


Source:



https://stackoverflow.com/a/1624689/1276374






share|improve this answer


























  • is there any thing except scale because if i scale the textView from one side, it does not look decreasing width, it look like comprising

    – Furqan
    Jul 31 '17 at 16:31



















2














Basically the idea is that, you calculate the new height (the height after your view increasing) view first and write an thread, increase the height of you old view (the height of your view before increasing) pixel by pixel(may be 5-10 pixels at a time) until it reaches the new height. Hope the idea could help.






share|improve this answer
























  • +1 for the idea.

    – Anukool
    Aug 7 '13 at 7:31



















0














You could write a for loop, where the view's height is increased by very little, than a pause is made before increasing the counter. In this way, the user will have the impression of a smooth transition.






share|improve this answer
























  • +1. for the input. I will try it out.

    – Anukool
    Aug 7 '13 at 7:31



















-1














Use



LinearLayout linearLayout = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);





share|improve this answer
























  • Doesn't compile, you're assigning a reference to an Object of type LinearLayout.LayoutParams to a variable of type LinearLayout.

    – urgentx
    May 23 '18 at 22:15












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f18097039%2fchange-view-height-programmatically-smoothly%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























4 Answers
4






active

oldest

votes








4 Answers
4






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Play with from/to/speed values



ScaleAnimation scaleAnimation = new ScaleAnimation(from, to, from, to, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rlOne.setAnimation(scaleAnimation);


Source:



https://stackoverflow.com/a/1624689/1276374






share|improve this answer


























  • is there any thing except scale because if i scale the textView from one side, it does not look decreasing width, it look like comprising

    – Furqan
    Jul 31 '17 at 16:31
















0














Play with from/to/speed values



ScaleAnimation scaleAnimation = new ScaleAnimation(from, to, from, to, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rlOne.setAnimation(scaleAnimation);


Source:



https://stackoverflow.com/a/1624689/1276374






share|improve this answer


























  • is there any thing except scale because if i scale the textView from one side, it does not look decreasing width, it look like comprising

    – Furqan
    Jul 31 '17 at 16:31














0












0








0







Play with from/to/speed values



ScaleAnimation scaleAnimation = new ScaleAnimation(from, to, from, to, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rlOne.setAnimation(scaleAnimation);


Source:



https://stackoverflow.com/a/1624689/1276374






share|improve this answer















Play with from/to/speed values



ScaleAnimation scaleAnimation = new ScaleAnimation(from, to, from, to, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rlOne.setAnimation(scaleAnimation);


Source:



https://stackoverflow.com/a/1624689/1276374







share|improve this answer














share|improve this answer



share|improve this answer








edited May 23 '17 at 12:06









Community

11




11










answered Aug 7 '13 at 7:43









Boris MocialovBoris Mocialov

2,60811648




2,60811648













  • is there any thing except scale because if i scale the textView from one side, it does not look decreasing width, it look like comprising

    – Furqan
    Jul 31 '17 at 16:31



















  • is there any thing except scale because if i scale the textView from one side, it does not look decreasing width, it look like comprising

    – Furqan
    Jul 31 '17 at 16:31

















is there any thing except scale because if i scale the textView from one side, it does not look decreasing width, it look like comprising

– Furqan
Jul 31 '17 at 16:31





is there any thing except scale because if i scale the textView from one side, it does not look decreasing width, it look like comprising

– Furqan
Jul 31 '17 at 16:31













2














Basically the idea is that, you calculate the new height (the height after your view increasing) view first and write an thread, increase the height of you old view (the height of your view before increasing) pixel by pixel(may be 5-10 pixels at a time) until it reaches the new height. Hope the idea could help.






share|improve this answer
























  • +1 for the idea.

    – Anukool
    Aug 7 '13 at 7:31
















2














Basically the idea is that, you calculate the new height (the height after your view increasing) view first and write an thread, increase the height of you old view (the height of your view before increasing) pixel by pixel(may be 5-10 pixels at a time) until it reaches the new height. Hope the idea could help.






share|improve this answer
























  • +1 for the idea.

    – Anukool
    Aug 7 '13 at 7:31














2












2








2







Basically the idea is that, you calculate the new height (the height after your view increasing) view first and write an thread, increase the height of you old view (the height of your view before increasing) pixel by pixel(may be 5-10 pixels at a time) until it reaches the new height. Hope the idea could help.






share|improve this answer













Basically the idea is that, you calculate the new height (the height after your view increasing) view first and write an thread, increase the height of you old view (the height of your view before increasing) pixel by pixel(may be 5-10 pixels at a time) until it reaches the new height. Hope the idea could help.







share|improve this answer












share|improve this answer



share|improve this answer










answered Aug 7 '13 at 7:24









user2652394user2652394

1,55411015




1,55411015













  • +1 for the idea.

    – Anukool
    Aug 7 '13 at 7:31



















  • +1 for the idea.

    – Anukool
    Aug 7 '13 at 7:31

















+1 for the idea.

– Anukool
Aug 7 '13 at 7:31





+1 for the idea.

– Anukool
Aug 7 '13 at 7:31











0














You could write a for loop, where the view's height is increased by very little, than a pause is made before increasing the counter. In this way, the user will have the impression of a smooth transition.






share|improve this answer
























  • +1. for the input. I will try it out.

    – Anukool
    Aug 7 '13 at 7:31
















0














You could write a for loop, where the view's height is increased by very little, than a pause is made before increasing the counter. In this way, the user will have the impression of a smooth transition.






share|improve this answer
























  • +1. for the input. I will try it out.

    – Anukool
    Aug 7 '13 at 7:31














0












0








0







You could write a for loop, where the view's height is increased by very little, than a pause is made before increasing the counter. In this way, the user will have the impression of a smooth transition.






share|improve this answer













You could write a for loop, where the view's height is increased by very little, than a pause is made before increasing the counter. In this way, the user will have the impression of a smooth transition.







share|improve this answer












share|improve this answer



share|improve this answer










answered Aug 7 '13 at 7:22









RaduRadu

324314




324314













  • +1. for the input. I will try it out.

    – Anukool
    Aug 7 '13 at 7:31



















  • +1. for the input. I will try it out.

    – Anukool
    Aug 7 '13 at 7:31

















+1. for the input. I will try it out.

– Anukool
Aug 7 '13 at 7:31





+1. for the input. I will try it out.

– Anukool
Aug 7 '13 at 7:31











-1














Use



LinearLayout linearLayout = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);





share|improve this answer
























  • Doesn't compile, you're assigning a reference to an Object of type LinearLayout.LayoutParams to a variable of type LinearLayout.

    – urgentx
    May 23 '18 at 22:15
















-1














Use



LinearLayout linearLayout = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);





share|improve this answer
























  • Doesn't compile, you're assigning a reference to an Object of type LinearLayout.LayoutParams to a variable of type LinearLayout.

    – urgentx
    May 23 '18 at 22:15














-1












-1








-1







Use



LinearLayout linearLayout = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);





share|improve this answer













Use



LinearLayout linearLayout = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);






share|improve this answer












share|improve this answer



share|improve this answer










answered Aug 7 '13 at 7:50









MasterMaster

2,07832657




2,07832657













  • Doesn't compile, you're assigning a reference to an Object of type LinearLayout.LayoutParams to a variable of type LinearLayout.

    – urgentx
    May 23 '18 at 22:15



















  • Doesn't compile, you're assigning a reference to an Object of type LinearLayout.LayoutParams to a variable of type LinearLayout.

    – urgentx
    May 23 '18 at 22:15

















Doesn't compile, you're assigning a reference to an Object of type LinearLayout.LayoutParams to a variable of type LinearLayout.

– urgentx
May 23 '18 at 22:15





Doesn't compile, you're assigning a reference to an Object of type LinearLayout.LayoutParams to a variable of type LinearLayout.

– urgentx
May 23 '18 at 22:15


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f18097039%2fchange-view-height-programmatically-smoothly%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

SQL update select statement

'app-layout' is not a known element: how to share Component with different Modules