Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shadow behind AutoFitTextView #31

Open
axelfran opened this issue May 13, 2016 · 8 comments
Open

Shadow behind AutoFitTextView #31

axelfran opened this issue May 13, 2016 · 8 comments

Comments

@axelfran
Copy link

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!

@AndroidDeveloperLB
Copy link
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.

@axelfran
Copy link
Author

Thanks! I will give this a try:)

@AndroidDeveloperLB
Copy link
Owner

Did it help?

@axelfran
Copy link
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

@AndroidDeveloperLB
Copy link
Owner

odd. thank you for trying to fix it.

@CrandellWS
Copy link

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

@AndroidDeveloperLB
Copy link
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 <[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
#31 (comment)

@CrandellWS
Copy link

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants