How do i auto adjust my item positions in a layout in android?












0















This is my Current Layout



enter image description here



I'm stuck in this issue for a couple of days now. As you can see in the image above. There are 10 items below those 3 buttons. Ignore the buttons please. 9 items are visible and 1 item is below them. its a ScrollView. What i want to do is to position all those 10 items according to each other so when i hide one or more items, the rest positions themselves accordingly. for example if i hide the 3 items from the 3rd row then the item on the 4th row comes into the 3rd row in first column, and if i hide all the items except 1 or two then they should place themselves in a single row next to each other. How can i achieve that. I have tried several layouts, maybe i have missed something but i haven't been able to achieve the auto adjust part with any layout. Any help would be highly appreciated,i just want to know what layout or what can help me to achieve this goal ?



So if i hide 2 items from these 10 items,Then it should look like this.



This is what i want to achieve



but if there is only one item then it should look like this.



If just one item then it should look like this










share|improve this question

























  • Use Gridview or RecyclerView with GridLayoutManager and inflate items dynamically.

    – rajesh
    Nov 22 '18 at 9:16













  • @rajesh Ive tried that but if there is only 1 card in my list then it will show that card at the position of 1st row and 1st column but what i want is that it should move to the center itself.

    – Muhammad Abdullah
    Nov 22 '18 at 9:52


















0















This is my Current Layout



enter image description here



I'm stuck in this issue for a couple of days now. As you can see in the image above. There are 10 items below those 3 buttons. Ignore the buttons please. 9 items are visible and 1 item is below them. its a ScrollView. What i want to do is to position all those 10 items according to each other so when i hide one or more items, the rest positions themselves accordingly. for example if i hide the 3 items from the 3rd row then the item on the 4th row comes into the 3rd row in first column, and if i hide all the items except 1 or two then they should place themselves in a single row next to each other. How can i achieve that. I have tried several layouts, maybe i have missed something but i haven't been able to achieve the auto adjust part with any layout. Any help would be highly appreciated,i just want to know what layout or what can help me to achieve this goal ?



So if i hide 2 items from these 10 items,Then it should look like this.



This is what i want to achieve



but if there is only one item then it should look like this.



If just one item then it should look like this










share|improve this question

























  • Use Gridview or RecyclerView with GridLayoutManager and inflate items dynamically.

    – rajesh
    Nov 22 '18 at 9:16













  • @rajesh Ive tried that but if there is only 1 card in my list then it will show that card at the position of 1st row and 1st column but what i want is that it should move to the center itself.

    – Muhammad Abdullah
    Nov 22 '18 at 9:52
















0












0








0








This is my Current Layout



enter image description here



I'm stuck in this issue for a couple of days now. As you can see in the image above. There are 10 items below those 3 buttons. Ignore the buttons please. 9 items are visible and 1 item is below them. its a ScrollView. What i want to do is to position all those 10 items according to each other so when i hide one or more items, the rest positions themselves accordingly. for example if i hide the 3 items from the 3rd row then the item on the 4th row comes into the 3rd row in first column, and if i hide all the items except 1 or two then they should place themselves in a single row next to each other. How can i achieve that. I have tried several layouts, maybe i have missed something but i haven't been able to achieve the auto adjust part with any layout. Any help would be highly appreciated,i just want to know what layout or what can help me to achieve this goal ?



So if i hide 2 items from these 10 items,Then it should look like this.



This is what i want to achieve



but if there is only one item then it should look like this.



If just one item then it should look like this










share|improve this question
















This is my Current Layout



enter image description here



I'm stuck in this issue for a couple of days now. As you can see in the image above. There are 10 items below those 3 buttons. Ignore the buttons please. 9 items are visible and 1 item is below them. its a ScrollView. What i want to do is to position all those 10 items according to each other so when i hide one or more items, the rest positions themselves accordingly. for example if i hide the 3 items from the 3rd row then the item on the 4th row comes into the 3rd row in first column, and if i hide all the items except 1 or two then they should place themselves in a single row next to each other. How can i achieve that. I have tried several layouts, maybe i have missed something but i haven't been able to achieve the auto adjust part with any layout. Any help would be highly appreciated,i just want to know what layout or what can help me to achieve this goal ?



So if i hide 2 items from these 10 items,Then it should look like this.



This is what i want to achieve



but if there is only one item then it should look like this.



If just one item then it should look like this







android user-interface layout






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 10:03







Muhammad Abdullah

















asked Nov 22 '18 at 8:28









Muhammad AbdullahMuhammad Abdullah

309




309













  • Use Gridview or RecyclerView with GridLayoutManager and inflate items dynamically.

    – rajesh
    Nov 22 '18 at 9:16













  • @rajesh Ive tried that but if there is only 1 card in my list then it will show that card at the position of 1st row and 1st column but what i want is that it should move to the center itself.

    – Muhammad Abdullah
    Nov 22 '18 at 9:52





















  • Use Gridview or RecyclerView with GridLayoutManager and inflate items dynamically.

    – rajesh
    Nov 22 '18 at 9:16













  • @rajesh Ive tried that but if there is only 1 card in my list then it will show that card at the position of 1st row and 1st column but what i want is that it should move to the center itself.

    – Muhammad Abdullah
    Nov 22 '18 at 9:52



















Use Gridview or RecyclerView with GridLayoutManager and inflate items dynamically.

– rajesh
Nov 22 '18 at 9:16







Use Gridview or RecyclerView with GridLayoutManager and inflate items dynamically.

– rajesh
Nov 22 '18 at 9:16















@rajesh Ive tried that but if there is only 1 card in my list then it will show that card at the position of 1st row and 1st column but what i want is that it should move to the center itself.

– Muhammad Abdullah
Nov 22 '18 at 9:52







@rajesh Ive tried that but if there is only 1 card in my list then it will show that card at the position of 1st row and 1st column but what i want is that it should move to the center itself.

– Muhammad Abdullah
Nov 22 '18 at 9:52














1 Answer
1






active

oldest

votes


















0














Use a RecyclerView. You can add and delete views inside RecyclerView with layout animations.It's easy than changing the visibility. please check it(Don't know what's your need)






share|improve this answer
























  • Here is the problem with that. If i have only one item in my list. whatever layout manager i use. It will show at the 1st position of that layout accordingly, but what i want is to show that item in the center of my fragment. Hope now you understand what i want to achieve.

    – Muhammad Abdullah
    Nov 22 '18 at 9:54











  • so what is the total number of items. Is it unknown?

    – ABr
    Nov 22 '18 at 10:03











  • Total items are 10, But i have to show them depending upon which item i need. it can be all 10 or just 1 or any number in between.

    – Muhammad Abdullah
    Nov 22 '18 at 10:05






  • 1





    so you can change the spancount to 1 when the listsize is 1, I think that will move the item to the center

    – ABr
    Nov 22 '18 at 10:17











  • Oh dear . How could i miss that . That worked .. Thanks.

    – Muhammad Abdullah
    Nov 22 '18 at 12:08











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%2f53426684%2fhow-do-i-auto-adjust-my-item-positions-in-a-layout-in-android%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Use a RecyclerView. You can add and delete views inside RecyclerView with layout animations.It's easy than changing the visibility. please check it(Don't know what's your need)






share|improve this answer
























  • Here is the problem with that. If i have only one item in my list. whatever layout manager i use. It will show at the 1st position of that layout accordingly, but what i want is to show that item in the center of my fragment. Hope now you understand what i want to achieve.

    – Muhammad Abdullah
    Nov 22 '18 at 9:54











  • so what is the total number of items. Is it unknown?

    – ABr
    Nov 22 '18 at 10:03











  • Total items are 10, But i have to show them depending upon which item i need. it can be all 10 or just 1 or any number in between.

    – Muhammad Abdullah
    Nov 22 '18 at 10:05






  • 1





    so you can change the spancount to 1 when the listsize is 1, I think that will move the item to the center

    – ABr
    Nov 22 '18 at 10:17











  • Oh dear . How could i miss that . That worked .. Thanks.

    – Muhammad Abdullah
    Nov 22 '18 at 12:08
















0














Use a RecyclerView. You can add and delete views inside RecyclerView with layout animations.It's easy than changing the visibility. please check it(Don't know what's your need)






share|improve this answer
























  • Here is the problem with that. If i have only one item in my list. whatever layout manager i use. It will show at the 1st position of that layout accordingly, but what i want is to show that item in the center of my fragment. Hope now you understand what i want to achieve.

    – Muhammad Abdullah
    Nov 22 '18 at 9:54











  • so what is the total number of items. Is it unknown?

    – ABr
    Nov 22 '18 at 10:03











  • Total items are 10, But i have to show them depending upon which item i need. it can be all 10 or just 1 or any number in between.

    – Muhammad Abdullah
    Nov 22 '18 at 10:05






  • 1





    so you can change the spancount to 1 when the listsize is 1, I think that will move the item to the center

    – ABr
    Nov 22 '18 at 10:17











  • Oh dear . How could i miss that . That worked .. Thanks.

    – Muhammad Abdullah
    Nov 22 '18 at 12:08














0












0








0







Use a RecyclerView. You can add and delete views inside RecyclerView with layout animations.It's easy than changing the visibility. please check it(Don't know what's your need)






share|improve this answer













Use a RecyclerView. You can add and delete views inside RecyclerView with layout animations.It's easy than changing the visibility. please check it(Don't know what's your need)







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 22 '18 at 9:02









ABrABr

28327




28327













  • Here is the problem with that. If i have only one item in my list. whatever layout manager i use. It will show at the 1st position of that layout accordingly, but what i want is to show that item in the center of my fragment. Hope now you understand what i want to achieve.

    – Muhammad Abdullah
    Nov 22 '18 at 9:54











  • so what is the total number of items. Is it unknown?

    – ABr
    Nov 22 '18 at 10:03











  • Total items are 10, But i have to show them depending upon which item i need. it can be all 10 or just 1 or any number in between.

    – Muhammad Abdullah
    Nov 22 '18 at 10:05






  • 1





    so you can change the spancount to 1 when the listsize is 1, I think that will move the item to the center

    – ABr
    Nov 22 '18 at 10:17











  • Oh dear . How could i miss that . That worked .. Thanks.

    – Muhammad Abdullah
    Nov 22 '18 at 12:08



















  • Here is the problem with that. If i have only one item in my list. whatever layout manager i use. It will show at the 1st position of that layout accordingly, but what i want is to show that item in the center of my fragment. Hope now you understand what i want to achieve.

    – Muhammad Abdullah
    Nov 22 '18 at 9:54











  • so what is the total number of items. Is it unknown?

    – ABr
    Nov 22 '18 at 10:03











  • Total items are 10, But i have to show them depending upon which item i need. it can be all 10 or just 1 or any number in between.

    – Muhammad Abdullah
    Nov 22 '18 at 10:05






  • 1





    so you can change the spancount to 1 when the listsize is 1, I think that will move the item to the center

    – ABr
    Nov 22 '18 at 10:17











  • Oh dear . How could i miss that . That worked .. Thanks.

    – Muhammad Abdullah
    Nov 22 '18 at 12:08

















Here is the problem with that. If i have only one item in my list. whatever layout manager i use. It will show at the 1st position of that layout accordingly, but what i want is to show that item in the center of my fragment. Hope now you understand what i want to achieve.

– Muhammad Abdullah
Nov 22 '18 at 9:54





Here is the problem with that. If i have only one item in my list. whatever layout manager i use. It will show at the 1st position of that layout accordingly, but what i want is to show that item in the center of my fragment. Hope now you understand what i want to achieve.

– Muhammad Abdullah
Nov 22 '18 at 9:54













so what is the total number of items. Is it unknown?

– ABr
Nov 22 '18 at 10:03





so what is the total number of items. Is it unknown?

– ABr
Nov 22 '18 at 10:03













Total items are 10, But i have to show them depending upon which item i need. it can be all 10 or just 1 or any number in between.

– Muhammad Abdullah
Nov 22 '18 at 10:05





Total items are 10, But i have to show them depending upon which item i need. it can be all 10 or just 1 or any number in between.

– Muhammad Abdullah
Nov 22 '18 at 10:05




1




1





so you can change the spancount to 1 when the listsize is 1, I think that will move the item to the center

– ABr
Nov 22 '18 at 10:17





so you can change the spancount to 1 when the listsize is 1, I think that will move the item to the center

– ABr
Nov 22 '18 at 10:17













Oh dear . How could i miss that . That worked .. Thanks.

– Muhammad Abdullah
Nov 22 '18 at 12:08





Oh dear . How could i miss that . That worked .. Thanks.

– Muhammad Abdullah
Nov 22 '18 at 12:08




















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%2f53426684%2fhow-do-i-auto-adjust-my-item-positions-in-a-layout-in-android%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

MongoDB - Not Authorized To Execute Command

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

Npm cannot find a required file even through it is in the searched directory