Skip to content

Shadow behind AutoFitTextView #31

Description

@axelfran

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!

Activity

  1. AndroidDeveloperLB commented on May 13, 2016

    @AndroidDeveloperLB
    Owner

    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.

  2. axelfran commented on May 18, 2016

    @axelfran
    Author

    Thanks! I will give this a try:)

  3. AndroidDeveloperLB commented on May 22, 2016

    @AndroidDeveloperLB
    Owner

    Did it help?

  4. axelfran commented on May 24, 2016

    @axelfran
    Author

    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

  5. AndroidDeveloperLB commented on May 24, 2016

    @AndroidDeveloperLB
    Owner

    odd. thank you for trying to fix it.

  6. CrandellWS commented on May 24, 2016

    @CrandellWS

    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);
        }
    }
    
  7. AndroidDeveloperLB commented on May 24, 2016

    @AndroidDeveloperLB
    Owner

    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

    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
    #31 (comment)

  8. CrandellWS commented on May 24, 2016

    @CrandellWS

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions