Nahro
Nahro

Reputation: 406

layout_height="wrap_content" isnt affected by its childrens' shadows?

As you know, when a button is pressed, the shadow automatically gets increased. But the parent layout doesn't get affected by that change, as resulting, the shadow gets 'clipped off' or 'cut off' (pressing the + button):

screenshot shadow cut off

How do I fix this in a proper way?

Note: This issue doesn't happen if I remove the android:gravity line of the root LinearLayout activity_main file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:paddingTop="20dp"
android:orientation="vertical">

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="num1"
        android:gravity="center_horizontal"/>2

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="num2"
        android:gravity="center_horizontal"/>

</LinearLayout>

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="test123333333"/>

</LinearLayout>

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:backgroundTint="#0ff"
        android:text="+"/>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:backgroundTint="#0ff"
        android:text="-"/>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:backgroundTint="#0ff"
        android:text="*"
        android:onClick="add"/>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:backgroundTint="#0ff"
        android:text="%"/>

</LinearLayout>

</LinearLayout>

Upvotes: 0

Views: 125

Answers (1)

dthulke
dthulke

Reputation: 949

The shadow of a view does not its size. If your shadow gets larger than your view it is clipped by default.

To solve your problem you have the following options:

  1. Add some padding to your Button such that the shadow is not clipped.
  2. Disable the clipping by setting the following attribute to false: android:clipToPadding="false"

Upvotes: 1

Related Questions