10

我已经使用这个实现了滑出导航。当前实施

内容应该在菜单列表的右边缘附近投下阴影;喜欢预期结果

我正在尝试通过向内容左边缘添加视图来添加阴影,但它不会显示出来。

任何有关如何执行此操作的线索将不胜感激。

4

3 回答 3

11

伙计们,我知道我迟到了,但我很难找到让我满意的这个问题的答案,所以我只想分享我的解决方案。首先,创建一个可绘制的 navbar_shadow.xml 并将其与其余的可绘制对象放在一起。它只是一个带有透明渐变的矩形。

<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient android:startColor="#111"
        android:endColor="#00000000">
    </gradient>
    <size
        android:height="@dimen/activity_vertical_margin"
        android:width="5dp">
    </size>
</shape>

然后,无论您在哪里实例化您的抽屉,使用您的 DrawerLayout 变量将其附加到您的抽屉。

mDrawerLayout.setDrawerShadow(R.drawable.navbar_shadow, Gravity.LEFT);

巴姆。无需逐行绘制或包含任何额外资源。您可以使用自己的 startColor 来匹配您的抽屉颜色,但 endColor 应保持 #00000000 因为它是透明的黑色。

于 2014-01-29T15:21:52.250 回答
1

我知道这篇文章已经很老了,但是我很难找到解决方案,所以我认为如果我在这里发布我的帖子可能会对某人有所帮助。

我想在这个简单的 ListView 的右侧添加淡入黑色。

<ListView
    android:id="@+id/sideMenuList"
    android:layout_width="300dp"
    android:layout_height="match_parent"/>

使用 GIMP创建了一个带有渐变的 PNG 文件。将其添加到 /res/drawable。我的被​​命名为 fade_from_right.png

用RelativeLayout 包围ListView。为 RelativeLayout 提供您希望 ListView 具有的背景颜色。

在 ListView 的右侧添加另一个视图。将新视图背景设置为您的“fade_from_right.png”

而已。

<RelativeLayout
    android:layout_height="match_parent"
    android:layout_width="300dp"
    android:background="@color/solarized_base02">

    <ListView
        android:id="@+id/sideMenuList"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <View
        android:layout_alignRight="@id/sideMenuList"
        android:layout_width="5dp"
        android:layout_height="match_parent"
        android:background="@drawable/fade_from_right"/>

</RelativeLayout>
于 2013-04-22T07:00:16.720 回答
0

有什么需要用列表视图添加另一个视图,我认为它不会是完美的..你可以这样尝试吗?

sm = getSlidingMenu();
sm.setShadowDrawable(R.drawable.shadowbar);

因为我们可能会设置一些 behindView 的宽度和偏移量。我认为这个选项会很好看。

于 2013-04-22T07:07:57.620 回答