AutoFitTextView icon indicating copy to clipboard operation
AutoFitTextView copied to clipboard

Shadow behind AutoFitTextView

Open axelfran opened this issue 8 years ago • 8 comments

Hi,

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?

Thanks in advance!

axelfran avatar May 13 '16 18:05 axelfran

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.

AndroidDeveloperLB avatar May 13 '16 19:05 AndroidDeveloperLB

Thanks! I will give this a try:)

axelfran avatar May 18 '16 08:05 axelfran

Did it help?

AndroidDeveloperLB avatar May 22 '16 07:05 AndroidDeveloperLB

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 image

axelfran avatar May 24 '16 19:05 axelfran

odd. thank you for trying to fix it.

AndroidDeveloperLB avatar May 24 '16 20:05 AndroidDeveloperLB

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

/*
 * 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);
    }
}

CrandellWS avatar May 24 '16 21:05 CrandellWS

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 <[email protected]

wrote:

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

/*

  • 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);
    

    } }

— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/AndroidDeveloperLB/AutoFitTextView/issues/31#issuecomment-221404579

AndroidDeveloperLB avatar May 24 '16 21:05 AndroidDeveloperLB

as stated

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

CrandellWS avatar May 24 '16 22:05 CrandellWS