close
先新增兩個imageView元件選擇不同的圖片並且把他們疊在一起
一般沒經過設定的情況下,元件顯示的前後方向主要是看ComPonent Tree裡面的排列
較下方排序會讓元件排列在前,但此方法在複雜的UI介面下絕對是不可靠的,所以在此示範簡易的元件置頂
所以今天會用到bringTofront()來控制元件的順序
先用ig2元件壓住ig元件,再藉由控制元件的Code讓ig元件顯示在前面
示範
XML
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <ImageView android:id="@+id/ig" android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:srcCompat="@android:drawable/btn_star_big_on" /> <ImageView android:id="@+id/ig2" android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.498" app:srcCompat="@mipmap/ic_launcher_round" /> </android.support.constraint.ConstraintLayout>
JAVA
public class MainActivity extends AppCompatActivity { ImageView ig,ig2; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ig =(ImageView)findViewById(R.id.ig); ig2 =(ImageView)findViewById(R.id.ig2); ig.bringToFront(); } }
相關文章:
[Android] Android 程式設計教學
本網站https://kk665403.pixnet.net/內之全部圖文,Saioyan梟夜所有,非經本人同意不得將全部或部分內容轉載於任何形式之媒體
Copyright © 2021 Saioyan. All rights reserved.
版權所有© 2021 Saioyan梟夜
文章標籤
全站熱搜