Dynamically set height of an EditText based on the content












0















I have an Edit text in which i am using setText to load the data on an edit form. Currently the editText height is fixed and if the text Is larger than the editText height i can't see the full text at once.
Is there a way based on the content i can dynamically set the height of an EditText.



Thanks in advance for your help and suggestions



Regards
R










share|improve this question


















  • 1





    show me your xml code for edittext

    – Ramesh Kumar
    Oct 14 '17 at 6:39
















0















I have an Edit text in which i am using setText to load the data on an edit form. Currently the editText height is fixed and if the text Is larger than the editText height i can't see the full text at once.
Is there a way based on the content i can dynamically set the height of an EditText.



Thanks in advance for your help and suggestions



Regards
R










share|improve this question


















  • 1





    show me your xml code for edittext

    – Ramesh Kumar
    Oct 14 '17 at 6:39














0












0








0








I have an Edit text in which i am using setText to load the data on an edit form. Currently the editText height is fixed and if the text Is larger than the editText height i can't see the full text at once.
Is there a way based on the content i can dynamically set the height of an EditText.



Thanks in advance for your help and suggestions



Regards
R










share|improve this question














I have an Edit text in which i am using setText to load the data on an edit form. Currently the editText height is fixed and if the text Is larger than the editText height i can't see the full text at once.
Is there a way based on the content i can dynamically set the height of an EditText.



Thanks in advance for your help and suggestions



Regards
R







android android-layout android-edittext






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Oct 14 '17 at 6:33









BRDroidBRDroid

69421333




69421333








  • 1





    show me your xml code for edittext

    – Ramesh Kumar
    Oct 14 '17 at 6:39














  • 1





    show me your xml code for edittext

    – Ramesh Kumar
    Oct 14 '17 at 6:39








1




1





show me your xml code for edittext

– Ramesh Kumar
Oct 14 '17 at 6:39





show me your xml code for edittext

– Ramesh Kumar
Oct 14 '17 at 6:39












5 Answers
5






active

oldest

votes


















2














try setting the height of edit text as following :



android:layout_height="wrap_content"





share|improve this answer































    4














    You can use this code for your xml file:



    <EditText
    android:id="@+id/edtFirstName"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="@string/first_name"
    android:padding="5dp"
    android:textColor="@color/black"
    android:textSize="16sp" />


    while your edit text contain comes it automatically fit the text size.



    Do not use android:singleLine="true" or android:minLines="1" and android:maxLines="1"






    share|improve this answer

































      2














      Set android:layout_height wrap_content is best Approach .




      The view should be only big enough to enclose its content .




      Use DisplayMetrics for Dynamically set the height of an EditText.



          DisplayMetrics metrics = getResources().getDisplayMetrics();

      int DeviceTotalWidth = metrics.widthPixels;
      int DeviceTotalHeight = metrics.heightPixels;


      How ?



      if(length()>n) // n is your String length
      editTEXT.getLayoutParams().height=DeviceTotalHeight*10/100;





      share|improve this answer

































        1














        Try, this one may help -:



          edittext.getLayoutParams().width=50




            et= (CustomEditText) findViewById(R.id.et);
        ViewGroup.LayoutParams lp = et.getLayoutParams();
        lp.width = 100;
        lp.height = 100;
        et.setLayoutParams(lp);





        share|improve this answer

































          1














          This may help you,



          Using android:layout_height ="wrap_content" and android:inputType="textMultiLine" are best approach



           <EditText
          android:id ="@+id/editText"
          android:layout_width ="match_parent"
          android:layout_height ="wrap_content"
          android:inputType="textMultiLine"
          android:hint ="Hint"
          android:scrollHorizontally="false" />


          I will suggest you to use ScrollView as a parent layout of EditText



          It prevents your EditText to cut off (outside from the screen) from screen when you have a larger text






          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%2f46741626%2fdynamically-set-height-of-an-edittext-based-on-the-content%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            5 Answers
            5






            active

            oldest

            votes








            5 Answers
            5






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2














            try setting the height of edit text as following :



            android:layout_height="wrap_content"





            share|improve this answer




























              2














              try setting the height of edit text as following :



              android:layout_height="wrap_content"





              share|improve this answer


























                2












                2








                2







                try setting the height of edit text as following :



                android:layout_height="wrap_content"





                share|improve this answer













                try setting the height of edit text as following :



                android:layout_height="wrap_content"






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Oct 14 '17 at 6:40









                Akhilesh AwasthiAkhilesh Awasthi

                1,67231223




                1,67231223

























                    4














                    You can use this code for your xml file:



                    <EditText
                    android:id="@+id/edtFirstName"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="@string/first_name"
                    android:padding="5dp"
                    android:textColor="@color/black"
                    android:textSize="16sp" />


                    while your edit text contain comes it automatically fit the text size.



                    Do not use android:singleLine="true" or android:minLines="1" and android:maxLines="1"






                    share|improve this answer






























                      4














                      You can use this code for your xml file:



                      <EditText
                      android:id="@+id/edtFirstName"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:hint="@string/first_name"
                      android:padding="5dp"
                      android:textColor="@color/black"
                      android:textSize="16sp" />


                      while your edit text contain comes it automatically fit the text size.



                      Do not use android:singleLine="true" or android:minLines="1" and android:maxLines="1"






                      share|improve this answer




























                        4












                        4








                        4







                        You can use this code for your xml file:



                        <EditText
                        android:id="@+id/edtFirstName"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:hint="@string/first_name"
                        android:padding="5dp"
                        android:textColor="@color/black"
                        android:textSize="16sp" />


                        while your edit text contain comes it automatically fit the text size.



                        Do not use android:singleLine="true" or android:minLines="1" and android:maxLines="1"






                        share|improve this answer















                        You can use this code for your xml file:



                        <EditText
                        android:id="@+id/edtFirstName"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:hint="@string/first_name"
                        android:padding="5dp"
                        android:textColor="@color/black"
                        android:textSize="16sp" />


                        while your edit text contain comes it automatically fit the text size.



                        Do not use android:singleLine="true" or android:minLines="1" and android:maxLines="1"







                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Nov 20 '18 at 6:21

























                        answered Oct 14 '17 at 6:53









                        Ramesh KumarRamesh Kumar

                        9641323




                        9641323























                            2














                            Set android:layout_height wrap_content is best Approach .




                            The view should be only big enough to enclose its content .




                            Use DisplayMetrics for Dynamically set the height of an EditText.



                                DisplayMetrics metrics = getResources().getDisplayMetrics();

                            int DeviceTotalWidth = metrics.widthPixels;
                            int DeviceTotalHeight = metrics.heightPixels;


                            How ?



                            if(length()>n) // n is your String length
                            editTEXT.getLayoutParams().height=DeviceTotalHeight*10/100;





                            share|improve this answer






























                              2














                              Set android:layout_height wrap_content is best Approach .




                              The view should be only big enough to enclose its content .




                              Use DisplayMetrics for Dynamically set the height of an EditText.



                                  DisplayMetrics metrics = getResources().getDisplayMetrics();

                              int DeviceTotalWidth = metrics.widthPixels;
                              int DeviceTotalHeight = metrics.heightPixels;


                              How ?



                              if(length()>n) // n is your String length
                              editTEXT.getLayoutParams().height=DeviceTotalHeight*10/100;





                              share|improve this answer




























                                2












                                2








                                2







                                Set android:layout_height wrap_content is best Approach .




                                The view should be only big enough to enclose its content .




                                Use DisplayMetrics for Dynamically set the height of an EditText.



                                    DisplayMetrics metrics = getResources().getDisplayMetrics();

                                int DeviceTotalWidth = metrics.widthPixels;
                                int DeviceTotalHeight = metrics.heightPixels;


                                How ?



                                if(length()>n) // n is your String length
                                editTEXT.getLayoutParams().height=DeviceTotalHeight*10/100;





                                share|improve this answer















                                Set android:layout_height wrap_content is best Approach .




                                The view should be only big enough to enclose its content .




                                Use DisplayMetrics for Dynamically set the height of an EditText.



                                    DisplayMetrics metrics = getResources().getDisplayMetrics();

                                int DeviceTotalWidth = metrics.widthPixels;
                                int DeviceTotalHeight = metrics.heightPixels;


                                How ?



                                if(length()>n) // n is your String length
                                editTEXT.getLayoutParams().height=DeviceTotalHeight*10/100;






                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited Oct 14 '17 at 7:00

























                                answered Oct 14 '17 at 6:53









                                IntelliJ AmiyaIntelliJ Amiya

                                53.3k12112134




                                53.3k12112134























                                    1














                                    Try, this one may help -:



                                      edittext.getLayoutParams().width=50




                                        et= (CustomEditText) findViewById(R.id.et);
                                    ViewGroup.LayoutParams lp = et.getLayoutParams();
                                    lp.width = 100;
                                    lp.height = 100;
                                    et.setLayoutParams(lp);





                                    share|improve this answer






























                                      1














                                      Try, this one may help -:



                                        edittext.getLayoutParams().width=50




                                          et= (CustomEditText) findViewById(R.id.et);
                                      ViewGroup.LayoutParams lp = et.getLayoutParams();
                                      lp.width = 100;
                                      lp.height = 100;
                                      et.setLayoutParams(lp);





                                      share|improve this answer




























                                        1












                                        1








                                        1







                                        Try, this one may help -:



                                          edittext.getLayoutParams().width=50




                                            et= (CustomEditText) findViewById(R.id.et);
                                        ViewGroup.LayoutParams lp = et.getLayoutParams();
                                        lp.width = 100;
                                        lp.height = 100;
                                        et.setLayoutParams(lp);





                                        share|improve this answer















                                        Try, this one may help -:



                                          edittext.getLayoutParams().width=50




                                            et= (CustomEditText) findViewById(R.id.et);
                                        ViewGroup.LayoutParams lp = et.getLayoutParams();
                                        lp.width = 100;
                                        lp.height = 100;
                                        et.setLayoutParams(lp);






                                        share|improve this answer














                                        share|improve this answer



                                        share|improve this answer








                                        edited Oct 14 '17 at 6:46









                                        UltimateDevil

                                        2,11321030




                                        2,11321030










                                        answered Oct 14 '17 at 6:43









                                        mehulmehul

                                        1,185416




                                        1,185416























                                            1














                                            This may help you,



                                            Using android:layout_height ="wrap_content" and android:inputType="textMultiLine" are best approach



                                             <EditText
                                            android:id ="@+id/editText"
                                            android:layout_width ="match_parent"
                                            android:layout_height ="wrap_content"
                                            android:inputType="textMultiLine"
                                            android:hint ="Hint"
                                            android:scrollHorizontally="false" />


                                            I will suggest you to use ScrollView as a parent layout of EditText



                                            It prevents your EditText to cut off (outside from the screen) from screen when you have a larger text






                                            share|improve this answer






























                                              1














                                              This may help you,



                                              Using android:layout_height ="wrap_content" and android:inputType="textMultiLine" are best approach



                                               <EditText
                                              android:id ="@+id/editText"
                                              android:layout_width ="match_parent"
                                              android:layout_height ="wrap_content"
                                              android:inputType="textMultiLine"
                                              android:hint ="Hint"
                                              android:scrollHorizontally="false" />


                                              I will suggest you to use ScrollView as a parent layout of EditText



                                              It prevents your EditText to cut off (outside from the screen) from screen when you have a larger text






                                              share|improve this answer




























                                                1












                                                1








                                                1







                                                This may help you,



                                                Using android:layout_height ="wrap_content" and android:inputType="textMultiLine" are best approach



                                                 <EditText
                                                android:id ="@+id/editText"
                                                android:layout_width ="match_parent"
                                                android:layout_height ="wrap_content"
                                                android:inputType="textMultiLine"
                                                android:hint ="Hint"
                                                android:scrollHorizontally="false" />


                                                I will suggest you to use ScrollView as a parent layout of EditText



                                                It prevents your EditText to cut off (outside from the screen) from screen when you have a larger text






                                                share|improve this answer















                                                This may help you,



                                                Using android:layout_height ="wrap_content" and android:inputType="textMultiLine" are best approach



                                                 <EditText
                                                android:id ="@+id/editText"
                                                android:layout_width ="match_parent"
                                                android:layout_height ="wrap_content"
                                                android:inputType="textMultiLine"
                                                android:hint ="Hint"
                                                android:scrollHorizontally="false" />


                                                I will suggest you to use ScrollView as a parent layout of EditText



                                                It prevents your EditText to cut off (outside from the screen) from screen when you have a larger text







                                                share|improve this answer














                                                share|improve this answer



                                                share|improve this answer








                                                edited Oct 14 '17 at 7:23

























                                                answered Oct 14 '17 at 7:02









                                                UltimateDevilUltimateDevil

                                                2,11321030




                                                2,11321030






























                                                    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%2f46741626%2fdynamically-set-height-of-an-edittext-based-on-the-content%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

                                                    How to pass form data using jquery Ajax to insert data in database?

                                                    National Museum of Racing and Hall of Fame

                                                    Guess what letter conforming each word