在this project(特徵/下拉陰影分支)我試圖添加上述的圖容器陰影。因此,我定義了以下形狀(drawable/shadow_above):陰影呈現不透明度
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#20000000"
android:endColor="@android:color/transparent"
android:angle="90">
</gradient>
</shape>
這然後在佈局文件(container_infos.xml)使用如下:
<View
android:background="@drawable/shadow_above"
android:layout_width="match_parent"
android:layout_height="4dp"/>
的屏幕截圖示出了結果。由於某種原因,投影看起來很糟糕。有不透明。我究竟做錯了什麼?隨意向我的開源項目發送拉請求。使用的RelativeLayout
解我設法用的RelativeLayout在fragment_map.xml來獲得期望的結果:
<?xml version="1.0" encoding="utf-8"?>
<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="vertical"
tools:context=".ui.MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<FrameLayout
android:id="@+id/map_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:background="@android:color/holo_purple"/>
<View
android:background="@drawable/shadow_above"
android:layout_alignBottom="@id/map_container"
android:layout_width="match_parent"
android:layout_height="4dp"/>
</RelativeLayout>
<include
layout="@layout/container_infos"/>
</LinearLayout>
可能有餘地優化。
你的觀點,梯度是在LinearLayout中。你確定這個觀點實際上高於別的嗎?我想你的意思是在地圖上留下陰影?如果沒有,那麼你的漸變角度就會指向錯誤的方向。底部是灰色的,頂部是透明的(背景照亮你的背景)。所以仔細檢查一下,你是否已經將漸變視圖放在需要的位置。 – 2014-12-07 15:08:41
是的。它實際上是在錯誤的地方。信息框向上滑動並移動地圖。目前,陰影視圖與默認背景合併。 - 因此,陰影必須放置在地圖上方。我覺得這必須通過編程來完成。應該是[* fragment_map.xml *]中的map_container之上的「圖層」(https://bitbucket.org/tbsprs/altglas/src/2b2dadc092efc781e619f64d229355a9fbc28230/app/src/main/res/layout/fragment_map.xml?在=特徵/下拉陰影)。 – JJD 2014-12-07 15:53:30