Having trouble adding a button to a GridLayout in my NativeScript application

My attempt to use a Button alongside some Images in a single row within a GridLayout resulted in the Button covering the entire row along with the images. Here is the HTML code I used:

<GridLayout columns="4*,*,*,*,*,*" rows="*">
    <Button text="send rating" (onTap)="rateIt()" col="0" row="0" class="send-rating-button"></Button>
    <Image src="{{ user_rating_imageurls[0] }}" col="1" row="0" class="star-image" (onTap)="rateFromUser('1')"></Image>
    <Image src="{{ user_rating_imageurls[1] }}" col="2" row="0" class="star-image" (onTap)="rateFromUser('2')"></Image>
    <Image src="{{ user_rating_imageurls[2] }}" col="3" row="0" class="star-image" (onTap)="rateFromUser('3')"></Image>
    <Image src="{{ user_rating_imageurls[3] }}" col="4" row="0" class="star-image" (onTap)="rateFromUser('4')"></Image>
    <Image src="{{ user_rating_imageurls[4] }}" col="5" row="0" class="star-image" (onTap)="rateFromUser('5')"></Image>
</GridLayout>

I suspected that there might be an issue with the way I defined the rows/columns, causing this layout problem. Additionally, here are the styles for the Button and Images:

.star-image {
    width: 30;
    margin: 10;
}

.send-rating-button {
    margin-left: 30;
    margin-right: 10;
    background-color: yellow;
    border-color:black;
    border-width: 1;
    max-width: 100;
}

After further review and experimentation, it turned out that instead of each element being placed in one cell of the GridLayout, they were all centered on top of each other. Here is the corrected code that now works as intended:

<GridLayout columns="*4,*,*,*,*,*" rows="*">
   <Button col="0" row="0" [text]="'RATING_AVG'|translate" class="send-rating-button" (onTap)="rateIt()"></Button>
    <Image src="{{ user_rating_imageurls[0] }}" col="1" row="0" class="star-image" (onTap)="rateFromUser('1')"></Image>
    <Image src="{{ user_rating_imageurls[1] }}" col="2" row="0" class="star-image" (onTap)="rateFromUser('2')"></Image>
    <Image src="{{ user_rating_imageurls[2] }}" col="3" row="0" class="star-image" (onTap)="rateFromUser('3')"></Image>
    <Image src="{{ user_rating_imageurls[3] }}" col="4" row="0" class="star-image" (onTap)="rateFromUser('4')"></Image>
    <Image src="{{ user_rating_imageurls[4] }}" col="5" row="0" class="star-image" (onTap)="rateFromUser('5')"></Image>
</GridLayout>

Answer №1

In Marek's comment, he pointed out that the issue is stemming from setting the first column to a width of 4 DP (device independent pixels) due to a syntax error. To rectify this, you can either increase the DP value for the first row or set a relative width using 4* (indicating that this column will be 4 times wider than columns set with *)

<GridLayout colums="4*,*,*,*,*,*" rows="*">

Answer №2

After some experimentation, I am still puzzled as to why the updated code is effective compared to the previous version. I have included the revised code in the original question for reference.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Determine the data type of a class property by referencing the data type of a different property within the

Why am I getting an error when assigning to this.propertyB in TypeScript? class Example { public readonly propertyA: boolean; private readonly propertyB: this['propertyA'] extends true ? null : 'value'; public constructor() ...

Interactive button visual effect

I have a piece of code that currently plays audio when I click on an image. However, I am looking to modify it so that not only does clicking on the image play the audio, but it also changes the image to another one. Can anyone assist me with this? Here i ...

unable to retrieve access-token and uid from the response headers

I am attempting to extract access-token and uid from the response headers of a post request, as shown in the screenshot at this https://i.sstatic.net/8w8pV.png Here is how I am approaching this task from the service side: signup(postObj: any){ let url = e ...

Building a versatile setting within a child component by incorporating TypeScript and deriving state data from the parent component

In my page component, I have set a state called formData. Now, I want to create a context within my form component so that I can utilize it in each child form component. Everything works smoothly without TypeScript. However, when using TypeScript, I encoun ...

What could be causing the white gap beneath my homepage?

I have successfully created a website that utilizes buttons for navigation, with everything working smoothly except for the homepage. On the homepage, there seems to be excessive white space below all the content. I attempted to fix this by setting overflo ...

button that smooth slides out using jquery

Here is the source code for a jQuery slideout: jQuery(function($) { $('#slideClick').toggle(function() { $(this).parent().animate({left:'0px'}, {queue:false, duration: 500}); }, function() { $(t ...

Declaring global types in a NX and NextJS monorepository for enhanced development consistency

I've been searching online to find a good solution for my issue, but so far I haven't had any luck. Currently, I have a NX monorepo with NextJS and I'm attempting to create a global types/ folder that can be accessed by all my apps and libs ...

What is preventing me from creating accurate drawings on canvas?

I'm currently working on a paint application and facing an issue. When I place the painting board on the left side of the screen, everything works fine and I can draw without any problems. However, when I move it to the right side of the screen, the m ...

What are the steps to clear a client's local cache after updating my website?

Is there a simple way to clear the cache of all players who have previously played my game? The game stats are stored in local storage, and some players experienced bugs when the stats were incorrect. This outdated data is now affecting the updated stats ...

What is the best way to determine Prisma types across various projects?

My current project has the following structure: dashboard -- prisma-project-1 -- prisma-project-2 -- client-of-prisma-project-1-and-prisma-project-2 This dashboard is designed to merge data from two separate databases and display them in a meaningful w ...

After resizing, a div with a height of 100% will scroll upwards

I have a single-page website consisting of three sections, each spanning the entire width and height of the window. While resizing the window on the first or last section, everything adjusts smoothly. However, when I am on the second section, things get a ...

Integrating blade code within blade code

Struggling to craft a button using the Form builder. {!! Form::button('<span style="color: {!! $colour[$i] !!}" class..') !!} The specific details of the button don't matter, all I wanted was to adjust the font color to $colour[$id]. Th ...

Unable to access external API through Jquery due to CORS error when making multipart formposts

There exists an external REST API used for uploading resources to a repository, which can be accessed via the curl command: curl -k -X POST -u username:password \ -F package_id="1234" \ -F file=@"path_to_a_file" \ https:/ ...

Utilize jQuery to find elements based on a specific attribute containing a certain value

I need help targeting specific attributes in links to append classes based on the file extension. My page displays various types of files, from images to .ppt files. I am using ASP.NET MVC and jQuery for this project. <a class="screenshot" title="" fil ...

How can I increase the space between an icon and text in my design?

I am currently facing challenges with incorporating Bootstrap alongside CSS and am in the process of familiarizing myself with Bootstrap documentation using Flex. I am struggling to create more space as the text continues to closely follow the icon when I ...

Mobile CSS Problem with Wordpress Header Image

Currently working on a website and facing an issue with the header resizing incorrectly on mobile devices. The header shifts to the right instead of staying centered above the navigation like it does on desktop screens. Below is the code snippet being used ...

Issues within html language

The formatting of this table is causing issues with printing <tr height="95%"> <td width="100%"> <div id="placeSchedule"> <table bgcolor="red" width="100%" height="100%" border="1"> <tr> < ...

Rearranging div placement based on the width of the screen

I am currently working on building a responsive website and I need two divs to switch positions depending on the screen width, both on initial load and when resizing. Despite my efforts in researching and trying various options, I have not been successful ...

If the first dropdown menu has a sub-element, then the user should be able to select the same value in the second dropdown menu using jQuery

To trigger an alert, two HTML select option dropdowns must both have the value DIP EDU. My current code successfully accomplishes this, but there is a scenario where some options in the first dropdown may contain sub-elements. For example, selecting MBA wi ...

Arranging h1 tags within a container id

Seeking assistance with aligning specific classes in a certain way: "left" should align to the left part of #header, "links" should be centered, and "right" should align to the right of #header. Additionally, I want the icons to align vertically with the t ...