You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I need to add a shadow behind the textview. The shadow has a quite large radius, so that it with my current solution will be clipped in many instances as the bounding box isn't increased when I add the shadow.
If this was a normal TextView I could just add some padding to it to avoid the clipping, however when I do that now the text becomes smaller. I would like to avoid that.
Anyone have any thoughts on how I should add padding without making the text smaller?
As a workaround, you might be able to put it inside a container view (FrameLayout, for example), and add the padding there, and set "clipChildren" to false on the it. Maybe it will work for now.
Perhaps rolling your own layout class may help... a base example for understanding forces the layout to be square. Perhaps you can rework the example to get your desired effect.
/*
* Copyright (C) 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.android.activityscenetransitionbasic;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.FrameLayout;
/**
* {@link android.widget.FrameLayout} which forces itself to be laid out as square.
*/
public class SquareFrameLayout extends FrameLayout {
public SquareFrameLayout(Context context) {
super(context);
}
public SquareFrameLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SquareFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public SquareFrameLayout(Context context, AttributeSet attrs,
int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
final int widthSize = MeasureSpec.getSize(widthMeasureSpec);
final int heightSize = MeasureSpec.getSize(heightMeasureSpec);
if (widthSize == 0 && heightSize == 0) {
// If there are no constraints on size, let FrameLayout measure
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
// Now use the smallest of the measured dimensions for both dimensions
final int minSize = Math.min(getMeasuredWidth(), getMeasuredHeight());
setMeasuredDimension(minSize, minSize);
return;
}
final int size;
if (widthSize == 0 || heightSize == 0) {
// If one of the dimensions has no restriction on size, set both dimensions to be the
// on that does
size = Math.max(widthSize, heightSize);
} else {
// Both dimensions have restrictions on size, set both dimensions to be the
// smallest of the two
size = Math.min(widthSize, heightSize);
}
final int newMeasureSpec = MeasureSpec.makeMeasureSpec(size, MeasureSpec.EXACTLY);
super.onMeasure(newMeasureSpec, newMeasureSpec);
}
}
Perhaps rolling your own layout class may help... a base example for
understanding forces the layout to be square. Perhaps you can rework the
example to get your desired effect.
{@link android.widget.FrameLayout} which forces itself to be laid out as square.
*/
public class SquareFrameLayout extends FrameLayout {
public SquareFrameLayout(Context context) {
super(context);
}
public SquareFrameLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SquareFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public SquareFrameLayout(Context context, AttributeSet attrs,
int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@OverRide
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
final int widthSize = MeasureSpec.getSize(widthMeasureSpec);
final int heightSize = MeasureSpec.getSize(heightMeasureSpec);
if (widthSize == 0 && heightSize == 0) {
// If there are no constraints on size, let FrameLayout measure
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
// Now use the smallest of the measured dimensions for both dimensions
final int minSize = Math.min(getMeasuredWidth(), getMeasuredHeight());
setMeasuredDimension(minSize, minSize);
return;
}
final int size;
if (widthSize == 0 || heightSize == 0) {
// If one of the dimensions has no restriction on size, set both dimensions to be the
// on that does
size = Math.max(widthSize, heightSize);
} else {
// Both dimensions have restrictions on size, set both dimensions to be the
// smallest of the two
size = Math.min(widthSize, heightSize);
}
final int newMeasureSpec = MeasureSpec.makeMeasureSpec(size, MeasureSpec.EXACTLY);
super.onMeasure(newMeasureSpec, newMeasureSpec);
}
}
—
You are receiving this because you commented.
Reply to this email directly or view it on GitHub #31 (comment)
put it inside a container view (FrameLayout, for example)
--@AndroidDeveloperLB
the example I posted shows how to force dimensions which may or may not be useful...hard to say without seeing how @axelfran is trying to get it done...so the example I provide maybe somewhat unrelated idk
Activity
AndroidDeveloperLB commentedon May 13, 2016
I thought this is already handled.
As a workaround, you might be able to put it inside a container view (FrameLayout, for example), and add the padding there, and set "clipChildren" to false on the it. Maybe it will work for now.
axelfran commentedon May 18, 2016
Thanks! I will give this a try:)
AndroidDeveloperLB commentedon May 22, 2016
Did it help?
axelfran commentedon May 24, 2016
No, unfortunately I haven't been able to make it work for my use case yet. As you can see the shadow still seems to be clipped on the top and bottom.
I will look deeper into this issue in the coming days, so will post an update then! :D

AndroidDeveloperLB commentedon May 24, 2016
odd. thank you for trying to fix it.
CrandellWS commentedon May 24, 2016
Perhaps rolling your own layout class may help... a base example for understanding forces the layout to be square. Perhaps you can rework the example to get your desired effect.
From -> https://developer.android.com/samples/ActivitySceneTransitionBasic/src/com.example.android.activityscenetransitionbasic/SquareFrameLayout.html
AndroidDeveloperLB commentedon May 24, 2016
I don't see why this solution should help, but you are free to try.
On Wed, May 25, 2016 at 12:36 AM, William Crandell <notifications@github.com
CrandellWS commentedon May 24, 2016
as stated
the example I posted shows how to force dimensions which may or may not be useful...hard to say without seeing how @axelfran is trying to get it done...so the example I provide maybe somewhat unrelated idk