我有两个高度相同的视图并排放置。我希望它们不会互相投射阴影,因为它们具有相同的高度。但实际情况是左边的视图会在右边投射阴影。它们大小不同,所以我不能将它们放在另一个视图中并给该视图应用高度。
这是预期的行为吗?有没有解决方法?
编辑:
我使用更简单的视图重新创建了一下,以下是代码。 我还注意到,如果我将视图直接放在布局中,而不像我在这个示例中那样包含它,则它具有预期的行为,正如我需要的那样。
这是预期的行为吗?有没有解决方法?
编辑:
我使用更简单的视图重新创建了一下,以下是代码。 我还注意到,如果我将视图直接放在布局中,而不像我在这个示例中那样包含它,则它具有预期的行为,正如我需要的那样。
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:background="@android:color/holo_green_dark">
<LinearLayout
android:layout_width="200dp"
android:layout_height="200dp"
android:background="@android:color/holo_red_dark"
android:elevation="24dp"/>
<include layout="@layout/test"/>
</LinearLayout>
这里是引用的内容:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@android:color/holo_red_dark"
android:elevation="24dp"/>
</LinearLayout>
而且这里有截图:
<include>
是您的问题,那么我怀疑解决方案是避免使用<include>
。例如,也许您可以创建一个自定义的View
/ViewGroup
,其中包含您的两个视图。 - CommonsWareFrameLayout
或RelativeLayout
而不是LinearLayout
时,会有什么行为?我认为阴影的表现会因此而异。嵌套和子布局也可能会影响阴影。 - Abtin Gramian