way 1
These two controls are placed in the RelativeLayout relative layout, whichever control is placed on top, the View instance of which control will call the bringToFront()
method. The example is as follows:
layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView android:id="@+id/wv_homepage"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<ProgressBar
android:id="@+id/pb_load_progress"
style="@android:style/Widget.Material.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_margin="0dp"
android:padding="0dp"
android:progress="0" />
</RelativeLayout>
Method call:
private lateinit var wvHomepage:WebView
private lateinit var pbLoadProgress:ProgressBar
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_goweb)
//获取控件
wvHomepage = findViewById(R.id.wv_homepage)
pbLoadProgress = findViewById(R.id.pb_load_progress)
//进度条控件放在WebView上面
pbLoadProgress.bringToFront()
}
way 2
With FrameLayout, the next view is stacked on top of the previous view, similar to a stack.
<FrameLayout android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="200dp"
android:layout_height="150dp"
android:background="#f00"/>
<TextView
android:layout_width="200dp"
android:layout_height="150dp"
android:background="#00f"
android:layout_marginLeft="100dp"
android:layout_marginTop="30dp"/>
</FrameLayout>
Note: To achieve a cascading effect, it is recommended to use a frame layout