TextView ShadowLayer being Clipped when Using WRAP_CONTENT












0















It's been a while since I've posted and I've read many posts to try to resolve my issue but I just can't seem to figure it out.
I am missing something and I hope someone can help me understand what I am doing wrong.



In this example I have a TextView inside a Linear Layout with the LayoutParams set to MATCH_PARENT.
If I use WRAP_CONTENT with the TextView the Shadow is being clipped, even if I use Padding.
If I set the TextView to MATCH_PARENT the shadow isn't clipped.



TextView WRAP_CONTENT No Padding:
TextView WRAP_CONTENT No Padding



TextView WRAP_CONTENT with Padding
Textview WRAP_CONTENT with Padding



TextView MATCH_PARENT:
TextView MATCH_PARENT



I've even tried it with
ll.setClipToPadding(false);
ll.setClipChildren(false);



What am I missing?










share|improve this question



























    0















    It's been a while since I've posted and I've read many posts to try to resolve my issue but I just can't seem to figure it out.
    I am missing something and I hope someone can help me understand what I am doing wrong.



    In this example I have a TextView inside a Linear Layout with the LayoutParams set to MATCH_PARENT.
    If I use WRAP_CONTENT with the TextView the Shadow is being clipped, even if I use Padding.
    If I set the TextView to MATCH_PARENT the shadow isn't clipped.



    TextView WRAP_CONTENT No Padding:
    TextView WRAP_CONTENT No Padding



    TextView WRAP_CONTENT with Padding
    Textview WRAP_CONTENT with Padding



    TextView MATCH_PARENT:
    TextView MATCH_PARENT



    I've even tried it with
    ll.setClipToPadding(false);
    ll.setClipChildren(false);



    What am I missing?










    share|improve this question

























      0












      0








      0








      It's been a while since I've posted and I've read many posts to try to resolve my issue but I just can't seem to figure it out.
      I am missing something and I hope someone can help me understand what I am doing wrong.



      In this example I have a TextView inside a Linear Layout with the LayoutParams set to MATCH_PARENT.
      If I use WRAP_CONTENT with the TextView the Shadow is being clipped, even if I use Padding.
      If I set the TextView to MATCH_PARENT the shadow isn't clipped.



      TextView WRAP_CONTENT No Padding:
      TextView WRAP_CONTENT No Padding



      TextView WRAP_CONTENT with Padding
      Textview WRAP_CONTENT with Padding



      TextView MATCH_PARENT:
      TextView MATCH_PARENT



      I've even tried it with
      ll.setClipToPadding(false);
      ll.setClipChildren(false);



      What am I missing?










      share|improve this question














      It's been a while since I've posted and I've read many posts to try to resolve my issue but I just can't seem to figure it out.
      I am missing something and I hope someone can help me understand what I am doing wrong.



      In this example I have a TextView inside a Linear Layout with the LayoutParams set to MATCH_PARENT.
      If I use WRAP_CONTENT with the TextView the Shadow is being clipped, even if I use Padding.
      If I set the TextView to MATCH_PARENT the shadow isn't clipped.



      TextView WRAP_CONTENT No Padding:
      TextView WRAP_CONTENT No Padding



      TextView WRAP_CONTENT with Padding
      Textview WRAP_CONTENT with Padding



      TextView MATCH_PARENT:
      TextView MATCH_PARENT



      I've even tried it with
      ll.setClipToPadding(false);
      ll.setClipChildren(false);



      What am I missing?







      android textview ondraw






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 2 at 21:14









      Ken NicholsKen Nichols

      6829




      6829
























          2 Answers
          2






          active

          oldest

          votes


















          1














          I don't think you're missing anything, unfortunately. This seems to be a bug with how TextView measures italic text. It's a problem even without shadows.



          enter image description here



          You'd have to subclass TextView (or AppCompatTextView) and define custom measuring behavior to work around this.



          If you don't want to bother with that, the consensus "best" answer is to add a non-breaking space to the end of your text in order to increase the measured size of the text. Unfortunately, this often adds more space than you really want.



          enter image description here



          Incidentally, android:clipToPadding is only an attribute on ViewGroup, which is why it doesn't do anything when you apply it to a TextView (it is simply ignored, like any other unknown attribute).






          share|improve this answer
























          • I played around with adding a space before and after the text and for smaller text sizes it works fine. Once you start using a large text size, as you stated, it consumes way to much real estate. Note: I was using .setClipToPadding and .setClipChildren on the LinearLayout which is the Parent View of the TextView.

            – Ken Nichols
            Jan 2 at 22:16






          • 1





            Ah, I misunderstood about your clipping strategy. Unfortunately, it is the TextView doing the clipping, so any clip attributes you set on the parent won't do anything in this case.

            – Ben P.
            Jan 2 at 22:20











          • Thanks for the help!

            – Ken Nichols
            Jan 2 at 22:27



















          0














          This is probably really bad practice but I went with the following:



          tv.setHeight(tv.getHeight() + tv.getPaddingTop() + tv.getPaddingBottom());
          tv.setWidth(tv.getWidth() + tv.getPaddingLeft() + tv.getPaddingRight());
          tv.setPadding(0, 0, 0, 0);


          Result:
          Result



          Thanks Again Ben for helping me!






          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%2f54013287%2ftextview-shadowlayer-being-clipped-when-using-wrap-content%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            I don't think you're missing anything, unfortunately. This seems to be a bug with how TextView measures italic text. It's a problem even without shadows.



            enter image description here



            You'd have to subclass TextView (or AppCompatTextView) and define custom measuring behavior to work around this.



            If you don't want to bother with that, the consensus "best" answer is to add a non-breaking space to the end of your text in order to increase the measured size of the text. Unfortunately, this often adds more space than you really want.



            enter image description here



            Incidentally, android:clipToPadding is only an attribute on ViewGroup, which is why it doesn't do anything when you apply it to a TextView (it is simply ignored, like any other unknown attribute).






            share|improve this answer
























            • I played around with adding a space before and after the text and for smaller text sizes it works fine. Once you start using a large text size, as you stated, it consumes way to much real estate. Note: I was using .setClipToPadding and .setClipChildren on the LinearLayout which is the Parent View of the TextView.

              – Ken Nichols
              Jan 2 at 22:16






            • 1





              Ah, I misunderstood about your clipping strategy. Unfortunately, it is the TextView doing the clipping, so any clip attributes you set on the parent won't do anything in this case.

              – Ben P.
              Jan 2 at 22:20











            • Thanks for the help!

              – Ken Nichols
              Jan 2 at 22:27
















            1














            I don't think you're missing anything, unfortunately. This seems to be a bug with how TextView measures italic text. It's a problem even without shadows.



            enter image description here



            You'd have to subclass TextView (or AppCompatTextView) and define custom measuring behavior to work around this.



            If you don't want to bother with that, the consensus "best" answer is to add a non-breaking space to the end of your text in order to increase the measured size of the text. Unfortunately, this often adds more space than you really want.



            enter image description here



            Incidentally, android:clipToPadding is only an attribute on ViewGroup, which is why it doesn't do anything when you apply it to a TextView (it is simply ignored, like any other unknown attribute).






            share|improve this answer
























            • I played around with adding a space before and after the text and for smaller text sizes it works fine. Once you start using a large text size, as you stated, it consumes way to much real estate. Note: I was using .setClipToPadding and .setClipChildren on the LinearLayout which is the Parent View of the TextView.

              – Ken Nichols
              Jan 2 at 22:16






            • 1





              Ah, I misunderstood about your clipping strategy. Unfortunately, it is the TextView doing the clipping, so any clip attributes you set on the parent won't do anything in this case.

              – Ben P.
              Jan 2 at 22:20











            • Thanks for the help!

              – Ken Nichols
              Jan 2 at 22:27














            1












            1








            1







            I don't think you're missing anything, unfortunately. This seems to be a bug with how TextView measures italic text. It's a problem even without shadows.



            enter image description here



            You'd have to subclass TextView (or AppCompatTextView) and define custom measuring behavior to work around this.



            If you don't want to bother with that, the consensus "best" answer is to add a non-breaking space to the end of your text in order to increase the measured size of the text. Unfortunately, this often adds more space than you really want.



            enter image description here



            Incidentally, android:clipToPadding is only an attribute on ViewGroup, which is why it doesn't do anything when you apply it to a TextView (it is simply ignored, like any other unknown attribute).






            share|improve this answer













            I don't think you're missing anything, unfortunately. This seems to be a bug with how TextView measures italic text. It's a problem even without shadows.



            enter image description here



            You'd have to subclass TextView (or AppCompatTextView) and define custom measuring behavior to work around this.



            If you don't want to bother with that, the consensus "best" answer is to add a non-breaking space to the end of your text in order to increase the measured size of the text. Unfortunately, this often adds more space than you really want.



            enter image description here



            Incidentally, android:clipToPadding is only an attribute on ViewGroup, which is why it doesn't do anything when you apply it to a TextView (it is simply ignored, like any other unknown attribute).







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jan 2 at 21:47









            Ben P.Ben P.

            24.9k32252




            24.9k32252













            • I played around with adding a space before and after the text and for smaller text sizes it works fine. Once you start using a large text size, as you stated, it consumes way to much real estate. Note: I was using .setClipToPadding and .setClipChildren on the LinearLayout which is the Parent View of the TextView.

              – Ken Nichols
              Jan 2 at 22:16






            • 1





              Ah, I misunderstood about your clipping strategy. Unfortunately, it is the TextView doing the clipping, so any clip attributes you set on the parent won't do anything in this case.

              – Ben P.
              Jan 2 at 22:20











            • Thanks for the help!

              – Ken Nichols
              Jan 2 at 22:27



















            • I played around with adding a space before and after the text and for smaller text sizes it works fine. Once you start using a large text size, as you stated, it consumes way to much real estate. Note: I was using .setClipToPadding and .setClipChildren on the LinearLayout which is the Parent View of the TextView.

              – Ken Nichols
              Jan 2 at 22:16






            • 1





              Ah, I misunderstood about your clipping strategy. Unfortunately, it is the TextView doing the clipping, so any clip attributes you set on the parent won't do anything in this case.

              – Ben P.
              Jan 2 at 22:20











            • Thanks for the help!

              – Ken Nichols
              Jan 2 at 22:27

















            I played around with adding a space before and after the text and for smaller text sizes it works fine. Once you start using a large text size, as you stated, it consumes way to much real estate. Note: I was using .setClipToPadding and .setClipChildren on the LinearLayout which is the Parent View of the TextView.

            – Ken Nichols
            Jan 2 at 22:16





            I played around with adding a space before and after the text and for smaller text sizes it works fine. Once you start using a large text size, as you stated, it consumes way to much real estate. Note: I was using .setClipToPadding and .setClipChildren on the LinearLayout which is the Parent View of the TextView.

            – Ken Nichols
            Jan 2 at 22:16




            1




            1





            Ah, I misunderstood about your clipping strategy. Unfortunately, it is the TextView doing the clipping, so any clip attributes you set on the parent won't do anything in this case.

            – Ben P.
            Jan 2 at 22:20





            Ah, I misunderstood about your clipping strategy. Unfortunately, it is the TextView doing the clipping, so any clip attributes you set on the parent won't do anything in this case.

            – Ben P.
            Jan 2 at 22:20













            Thanks for the help!

            – Ken Nichols
            Jan 2 at 22:27





            Thanks for the help!

            – Ken Nichols
            Jan 2 at 22:27













            0














            This is probably really bad practice but I went with the following:



            tv.setHeight(tv.getHeight() + tv.getPaddingTop() + tv.getPaddingBottom());
            tv.setWidth(tv.getWidth() + tv.getPaddingLeft() + tv.getPaddingRight());
            tv.setPadding(0, 0, 0, 0);


            Result:
            Result



            Thanks Again Ben for helping me!






            share|improve this answer




























              0














              This is probably really bad practice but I went with the following:



              tv.setHeight(tv.getHeight() + tv.getPaddingTop() + tv.getPaddingBottom());
              tv.setWidth(tv.getWidth() + tv.getPaddingLeft() + tv.getPaddingRight());
              tv.setPadding(0, 0, 0, 0);


              Result:
              Result



              Thanks Again Ben for helping me!






              share|improve this answer


























                0












                0








                0







                This is probably really bad practice but I went with the following:



                tv.setHeight(tv.getHeight() + tv.getPaddingTop() + tv.getPaddingBottom());
                tv.setWidth(tv.getWidth() + tv.getPaddingLeft() + tv.getPaddingRight());
                tv.setPadding(0, 0, 0, 0);


                Result:
                Result



                Thanks Again Ben for helping me!






                share|improve this answer













                This is probably really bad practice but I went with the following:



                tv.setHeight(tv.getHeight() + tv.getPaddingTop() + tv.getPaddingBottom());
                tv.setWidth(tv.getWidth() + tv.getPaddingLeft() + tv.getPaddingRight());
                tv.setPadding(0, 0, 0, 0);


                Result:
                Result



                Thanks Again Ben for helping me!







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 3 at 0:36









                Ken NicholsKen Nichols

                6829




                6829






























                    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%2f54013287%2ftextview-shadowlayer-being-clipped-when-using-wrap-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

                    MongoDB - Not Authorized To Execute Command

                    How to fix TextFormField cause rebuild widget in Flutter

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