TextView ShadowLayer being Clipped when Using WRAP_CONTENT
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 with Padding

TextView MATCH_PARENT:

I've even tried it with
ll.setClipToPadding(false);
ll.setClipChildren(false);
What am I missing?
add a comment |
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 with Padding

TextView MATCH_PARENT:

I've even tried it with
ll.setClipToPadding(false);
ll.setClipChildren(false);
What am I missing?
add a comment |
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 with Padding

TextView MATCH_PARENT:

I've even tried it with
ll.setClipToPadding(false);
ll.setClipChildren(false);
What am I missing?
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 with Padding

TextView MATCH_PARENT:

I've even tried it with
ll.setClipToPadding(false);
ll.setClipChildren(false);
What am I missing?
asked Jan 2 at 21:14
Ken NicholsKen Nichols
6829
6829
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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.

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.

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).
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
add a comment |
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:

Thanks Again Ben for helping me!
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.

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.

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).
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
add a comment |
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.

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.

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).
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
add a comment |
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.

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.

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).
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.

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.

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).
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
add a comment |
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
add a comment |
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:

Thanks Again Ben for helping me!
add a comment |
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:

Thanks Again Ben for helping me!
add a comment |
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:

Thanks Again Ben for helping me!
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:

Thanks Again Ben for helping me!
answered Jan 3 at 0:36
Ken NicholsKen Nichols
6829
6829
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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

