C0D*_*OU5 11
伙计们,我知道我迟到了,但我很难找到一个令我满意的问题的答案,所以我只想分享我的解决方案.拳头,创建一个可绘制的navbar_shadow.xml并将其与其余的drawable一起放置.它只是一个透明渐变的矩形.
<?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>
Run Code Online (Sandbox Code Playgroud)
然后,无论您在何处实例化抽屉,请使用DrawerLayout变量将其附加到抽屉.
mDrawerLayout.setDrawerShadow(R.drawable.navbar_shadow, Gravity.LEFT);
Run Code Online (Sandbox Code Playgroud)
巴姆.无需逐行绘制或包含任何额外资源.您可以使用自己的startColor来匹配抽屉颜色,但endColor应保持#00000000,因为它是透明的黑色.
我知道这篇文章已经很老了,但我很难找到解决方案,所以我想如果我在这里发布我的解决方案可能会对某人有所帮助。
我想在这个简单的 ListView 的右侧添加淡入黑色效果。
<ListView
android:id="@+id/sideMenuList"
android:layout_width="300dp"
android:layout_height="match_parent"/>
Run Code Online (Sandbox Code Playgroud)
使用 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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5333 次 |
| 最近记录: |