1.子控件相对于父布局的透明显示。
例如:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF0000">
<View
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#66000000"/>
</LinearLayout>
网上一般都是这个类型的,很容易就能搜到。
2.控件相对与兄弟控件的透明显示。
例如:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF0000"/>
<View
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#66000000"/>
</FrameLayout>
- 两个例子的效果图都是一样的。
这个要在FrameLayout这个布局类型里实现,之前为了做到在地图上方显示一行半透明字幕找了好久,都是第一种情况的,不能半透明显示,最后才发现用FrameLayout,发现好简单。
认识到:android各种布局都有各自的用处。