How do I set my button's height so it's the same as the width?Set ImageView width and height programmatically?combining wrap_content on parent and fill_parent on childHow to make buttons, with dynamic text, the same size and width to height ratio?how to set width which is equal to another widget on androidHow do i set cell height to be as it's width in android TableLayout?How do I set the height of an element to the same as another element?Set button height equal to the button widthDisable Tabs in TabLayoutSet project wide default for layout_width and layout_heightHow to specify in XML a percentage of width and height for a view?

Can anyone give me examples of the relative-determinative 'which'?

Why is the marginal distribution/marginal probability described as "marginal"?

Why did the soldiers of the North disobey Jon?

Why doesn't Iron Man's action affect this person in Endgame?

Is the seat-belt sign activation when a pilot goes to the lavatory standard procedure?

Which creature is depicted in this Xanathar's Guide illustration of a war mage?

What is this weird d12 for?

What do you call the hair or body hair you trim off your body?

How does Ctrl+c and Ctrl+v work?

Could a space colony 1g from the sun work?

Can my American children re-enter the USA by International flight with a passport card? Being that their passport book has expired

How much outgoing traffic would a HTTP load balance use?

Will there be more tax deductions if I put the house completely under my name, versus doing a joint ownership?

Was the dragon prowess intentionally downplayed in S08E04?

Does it matter what way the tires go if no directional arrow?

It is as easy as A B C, Figure out U V C from the given relationship

UUID type for NEWID()

What was Varys trying to do at the beginning of S08E05?

How does a permutation act on a string?

Does the wearer know what items are in which patch in the Robe of Useful items?

Why do galaxies collide?

Can a tourist shoot a gun in the USA?

Getting a similar picture (colours) on Manual Mode while using similar Auto Mode settings (T6 and 40D)

Understanding Python syntax in lists vs series



How do I set my button's height so it's the same as the width?


Set ImageView width and height programmatically?combining wrap_content on parent and fill_parent on childHow to make buttons, with dynamic text, the same size and width to height ratio?how to set width which is equal to another widget on androidHow do i set cell height to be as it's width in android TableLayout?How do I set the height of an element to the same as another element?Set button height equal to the button widthDisable Tabs in TabLayoutSet project wide default for layout_width and layout_heightHow to specify in XML a percentage of width and height for a view?






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








-1















I have a couple of buttons, that are supposed to be squares. But I'm not able to set the height to be the same as the width. How do I do that?



I tried to solve the problem with layout_constraintDimensionRatio, but it didn't work, the height was just 0.



This is the code:



<Button
android:id="@+id/grid_11"
style="@style/Widget.AppCompat.Button.Small"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"></Button>


And this is what I tried:



<Button
android:id="@+id/grid_11"
style="@style/Widget.AppCompat.Button.Small"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="1:1"
android:layout_weight="1"></Button>









share|improve this question




























    -1















    I have a couple of buttons, that are supposed to be squares. But I'm not able to set the height to be the same as the width. How do I do that?



    I tried to solve the problem with layout_constraintDimensionRatio, but it didn't work, the height was just 0.



    This is the code:



    <Button
    android:id="@+id/grid_11"
    style="@style/Widget.AppCompat.Button.Small"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"></Button>


    And this is what I tried:



    <Button
    android:id="@+id/grid_11"
    style="@style/Widget.AppCompat.Button.Small"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    app:layout_constraintDimensionRatio="1:1"
    android:layout_weight="1"></Button>









    share|improve this question
























      -1












      -1








      -1


      1






      I have a couple of buttons, that are supposed to be squares. But I'm not able to set the height to be the same as the width. How do I do that?



      I tried to solve the problem with layout_constraintDimensionRatio, but it didn't work, the height was just 0.



      This is the code:



      <Button
      android:id="@+id/grid_11"
      style="@style/Widget.AppCompat.Button.Small"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_weight="1"></Button>


      And this is what I tried:



      <Button
      android:id="@+id/grid_11"
      style="@style/Widget.AppCompat.Button.Small"
      android:layout_width="match_parent"
      android:layout_height="0dp"
      app:layout_constraintDimensionRatio="1:1"
      android:layout_weight="1"></Button>









      share|improve this question














      I have a couple of buttons, that are supposed to be squares. But I'm not able to set the height to be the same as the width. How do I do that?



      I tried to solve the problem with layout_constraintDimensionRatio, but it didn't work, the height was just 0.



      This is the code:



      <Button
      android:id="@+id/grid_11"
      style="@style/Widget.AppCompat.Button.Small"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_weight="1"></Button>


      And this is what I tried:



      <Button
      android:id="@+id/grid_11"
      style="@style/Widget.AppCompat.Button.Small"
      android:layout_width="match_parent"
      android:layout_height="0dp"
      app:layout_constraintDimensionRatio="1:1"
      android:layout_weight="1"></Button>






      android xml button size






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 23 at 15:18









      ywgymywgym

      11




      11






















          4 Answers
          4






          active

          oldest

          votes


















          1














          The reason the height was "0" is because you have not properly set the constraints for your button. Set proper constraints something as below and it will work.



          <Button
          android:id="@+id/grid_11"
          style="@style/Widget.AppCompat.Button.Small"
          android:layout_width="0dp"
          android:layout_height="0dp"
          app:layout_constraintTop_toTopOf="parent"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintDimensionRatio="1:1"/>





          share|improve this answer


















          • 2





            Note: this would only work if the parent view is a ContraintLayout

            – Gabe Sechan
            Mar 23 at 18:32



















          0














          This can be achieved by using values from the dimens file. If it is not present in the res/values folder, then create a XML file called dimens.xml file there. Then add a dimen value stating your value which you want to use for the height and width of the button:



          <dimen name="btn_size">100dp</dimen>


          Then you can specify it to the button like this:



          <Button
          android:id="@+id/grid_11"
          style="@style/Widget.AppCompat.Button.Small"
          android:layout_width="@dimen/btn_size"
          android:layout_height="@dimen/btn_size"
          android:layout_weight="1"></Button>


          This will add the same height width to the button.






          share|improve this answer























          • But what if I don't want the button to be a specific size? I want it to fit into the layout, so the width must stay match_parent.

            – ywgym
            Mar 23 at 15:42


















          0














          Change-



          android:layout_width="wrap_content"
          android:layout_height="wrap_content"


          To-



          android:layout_width="@dimen/square_button_size"
          android:layout_height="@dimen/square_button_size"


          and add



          <dimen name="square_button_size">50dp</dimen>


          in res/values/dimen.xml






          share|improve this answer
































            0














            If you don't want to put it in a ConstraintLayout (which is the easiest answer, @SirkarReddy already suggested it)- subclass Button and override the onMeasure function so that it will always measure itself as a square. There is no built in way to get the behavior you want in a RelativeLayout or LinearLayout without some hacking in code.






            share|improve this answer























              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%2f55315227%2fhow-do-i-set-my-buttons-height-so-its-the-same-as-the-width%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









              1














              The reason the height was "0" is because you have not properly set the constraints for your button. Set proper constraints something as below and it will work.



              <Button
              android:id="@+id/grid_11"
              style="@style/Widget.AppCompat.Button.Small"
              android:layout_width="0dp"
              android:layout_height="0dp"
              app:layout_constraintTop_toTopOf="parent"
              app:layout_constraintEnd_toEndOf="parent"
              app:layout_constraintStart_toStartOf="parent"
              app:layout_constraintDimensionRatio="1:1"/>





              share|improve this answer


















              • 2





                Note: this would only work if the parent view is a ContraintLayout

                – Gabe Sechan
                Mar 23 at 18:32
















              1














              The reason the height was "0" is because you have not properly set the constraints for your button. Set proper constraints something as below and it will work.



              <Button
              android:id="@+id/grid_11"
              style="@style/Widget.AppCompat.Button.Small"
              android:layout_width="0dp"
              android:layout_height="0dp"
              app:layout_constraintTop_toTopOf="parent"
              app:layout_constraintEnd_toEndOf="parent"
              app:layout_constraintStart_toStartOf="parent"
              app:layout_constraintDimensionRatio="1:1"/>





              share|improve this answer


















              • 2





                Note: this would only work if the parent view is a ContraintLayout

                – Gabe Sechan
                Mar 23 at 18:32














              1












              1








              1







              The reason the height was "0" is because you have not properly set the constraints for your button. Set proper constraints something as below and it will work.



              <Button
              android:id="@+id/grid_11"
              style="@style/Widget.AppCompat.Button.Small"
              android:layout_width="0dp"
              android:layout_height="0dp"
              app:layout_constraintTop_toTopOf="parent"
              app:layout_constraintEnd_toEndOf="parent"
              app:layout_constraintStart_toStartOf="parent"
              app:layout_constraintDimensionRatio="1:1"/>





              share|improve this answer













              The reason the height was "0" is because you have not properly set the constraints for your button. Set proper constraints something as below and it will work.



              <Button
              android:id="@+id/grid_11"
              style="@style/Widget.AppCompat.Button.Small"
              android:layout_width="0dp"
              android:layout_height="0dp"
              app:layout_constraintTop_toTopOf="parent"
              app:layout_constraintEnd_toEndOf="parent"
              app:layout_constraintStart_toStartOf="parent"
              app:layout_constraintDimensionRatio="1:1"/>






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Mar 23 at 15:38









              Srikar ReddySrikar Reddy

              1,96022441




              1,96022441







              • 2





                Note: this would only work if the parent view is a ContraintLayout

                – Gabe Sechan
                Mar 23 at 18:32













              • 2





                Note: this would only work if the parent view is a ContraintLayout

                – Gabe Sechan
                Mar 23 at 18:32








              2




              2





              Note: this would only work if the parent view is a ContraintLayout

              – Gabe Sechan
              Mar 23 at 18:32






              Note: this would only work if the parent view is a ContraintLayout

              – Gabe Sechan
              Mar 23 at 18:32














              0














              This can be achieved by using values from the dimens file. If it is not present in the res/values folder, then create a XML file called dimens.xml file there. Then add a dimen value stating your value which you want to use for the height and width of the button:



              <dimen name="btn_size">100dp</dimen>


              Then you can specify it to the button like this:



              <Button
              android:id="@+id/grid_11"
              style="@style/Widget.AppCompat.Button.Small"
              android:layout_width="@dimen/btn_size"
              android:layout_height="@dimen/btn_size"
              android:layout_weight="1"></Button>


              This will add the same height width to the button.






              share|improve this answer























              • But what if I don't want the button to be a specific size? I want it to fit into the layout, so the width must stay match_parent.

                – ywgym
                Mar 23 at 15:42















              0














              This can be achieved by using values from the dimens file. If it is not present in the res/values folder, then create a XML file called dimens.xml file there. Then add a dimen value stating your value which you want to use for the height and width of the button:



              <dimen name="btn_size">100dp</dimen>


              Then you can specify it to the button like this:



              <Button
              android:id="@+id/grid_11"
              style="@style/Widget.AppCompat.Button.Small"
              android:layout_width="@dimen/btn_size"
              android:layout_height="@dimen/btn_size"
              android:layout_weight="1"></Button>


              This will add the same height width to the button.






              share|improve this answer























              • But what if I don't want the button to be a specific size? I want it to fit into the layout, so the width must stay match_parent.

                – ywgym
                Mar 23 at 15:42













              0












              0








              0







              This can be achieved by using values from the dimens file. If it is not present in the res/values folder, then create a XML file called dimens.xml file there. Then add a dimen value stating your value which you want to use for the height and width of the button:



              <dimen name="btn_size">100dp</dimen>


              Then you can specify it to the button like this:



              <Button
              android:id="@+id/grid_11"
              style="@style/Widget.AppCompat.Button.Small"
              android:layout_width="@dimen/btn_size"
              android:layout_height="@dimen/btn_size"
              android:layout_weight="1"></Button>


              This will add the same height width to the button.






              share|improve this answer













              This can be achieved by using values from the dimens file. If it is not present in the res/values folder, then create a XML file called dimens.xml file there. Then add a dimen value stating your value which you want to use for the height and width of the button:



              <dimen name="btn_size">100dp</dimen>


              Then you can specify it to the button like this:



              <Button
              android:id="@+id/grid_11"
              style="@style/Widget.AppCompat.Button.Small"
              android:layout_width="@dimen/btn_size"
              android:layout_height="@dimen/btn_size"
              android:layout_weight="1"></Button>


              This will add the same height width to the button.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Mar 23 at 15:38









              GouravGourav

              97531031




              97531031












              • But what if I don't want the button to be a specific size? I want it to fit into the layout, so the width must stay match_parent.

                – ywgym
                Mar 23 at 15:42

















              • But what if I don't want the button to be a specific size? I want it to fit into the layout, so the width must stay match_parent.

                – ywgym
                Mar 23 at 15:42
















              But what if I don't want the button to be a specific size? I want it to fit into the layout, so the width must stay match_parent.

              – ywgym
              Mar 23 at 15:42





              But what if I don't want the button to be a specific size? I want it to fit into the layout, so the width must stay match_parent.

              – ywgym
              Mar 23 at 15:42











              0














              Change-



              android:layout_width="wrap_content"
              android:layout_height="wrap_content"


              To-



              android:layout_width="@dimen/square_button_size"
              android:layout_height="@dimen/square_button_size"


              and add



              <dimen name="square_button_size">50dp</dimen>


              in res/values/dimen.xml






              share|improve this answer





























                0














                Change-



                android:layout_width="wrap_content"
                android:layout_height="wrap_content"


                To-



                android:layout_width="@dimen/square_button_size"
                android:layout_height="@dimen/square_button_size"


                and add



                <dimen name="square_button_size">50dp</dimen>


                in res/values/dimen.xml






                share|improve this answer



























                  0












                  0








                  0







                  Change-



                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"


                  To-



                  android:layout_width="@dimen/square_button_size"
                  android:layout_height="@dimen/square_button_size"


                  and add



                  <dimen name="square_button_size">50dp</dimen>


                  in res/values/dimen.xml






                  share|improve this answer















                  Change-



                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"


                  To-



                  android:layout_width="@dimen/square_button_size"
                  android:layout_height="@dimen/square_button_size"


                  and add



                  <dimen name="square_button_size">50dp</dimen>


                  in res/values/dimen.xml







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Mar 23 at 15:39









                  forpas

                  25.1k4830




                  25.1k4830










                  answered Mar 23 at 15:33









                  H_KH_K

                  13




                  13





















                      0














                      If you don't want to put it in a ConstraintLayout (which is the easiest answer, @SirkarReddy already suggested it)- subclass Button and override the onMeasure function so that it will always measure itself as a square. There is no built in way to get the behavior you want in a RelativeLayout or LinearLayout without some hacking in code.






                      share|improve this answer



























                        0














                        If you don't want to put it in a ConstraintLayout (which is the easiest answer, @SirkarReddy already suggested it)- subclass Button and override the onMeasure function so that it will always measure itself as a square. There is no built in way to get the behavior you want in a RelativeLayout or LinearLayout without some hacking in code.






                        share|improve this answer

























                          0












                          0








                          0







                          If you don't want to put it in a ConstraintLayout (which is the easiest answer, @SirkarReddy already suggested it)- subclass Button and override the onMeasure function so that it will always measure itself as a square. There is no built in way to get the behavior you want in a RelativeLayout or LinearLayout without some hacking in code.






                          share|improve this answer













                          If you don't want to put it in a ConstraintLayout (which is the easiest answer, @SirkarReddy already suggested it)- subclass Button and override the onMeasure function so that it will always measure itself as a square. There is no built in way to get the behavior you want in a RelativeLayout or LinearLayout without some hacking in code.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Mar 23 at 18:34









                          Gabe SechanGabe Sechan

                          69.1k966102




                          69.1k966102



























                              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%2f55315227%2fhow-do-i-set-my-buttons-height-so-its-the-same-as-the-width%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

                              Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                              SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                              은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현