Change Superlative At Run-Time, Past Times Calling Setz()

Posted on

This event demo how to change elevation of ImageView programmatically, past times calling setZ().

<?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:padding="16dp"     android:orientation="vertical"     tools:context="com.blogspot.android_er.androidzelevation.MainActivity">      <TextView         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_margin="20dp"         android:layout_gravity="center_horizontal"         android:autoLink="web"         android:text="https://rootandroid.org//"         android:textStyle="bold"/>      <SeekBar         android:id="@+id/z"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:progress="20"         android:max="100"/>      <LinearLayout         android:layout_width="match_parent"         android:layout_height="0dp"         android:layout_weight="1"         android:orientation="vertical"         android:gravity="center">         <ImageView             android:id="@+id/image"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:elevation="20dp"             android:background="@android:color/background_dark"             android:src="@mipmap/ic_launcher"/>     </LinearLayout>  </LinearLayout>  
package com.blogspot.android_er.androidzelevation;  import android.os.Build; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.widget.ImageView; import android.widget.SeekBar;  world aeroplane MainActivity extends AppCompatActivity {      SeekBar seekBarZ;     ImageView image;      @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_main);          seekBarZ = (SeekBar)findViewById(R.id.z);         picture = (ImageView)findViewById(R.id.image);                  seekBarZ.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {             @Override             world void onProgressChanged(SeekBar seekBar, int i, boolean b) {                 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {                     image.setZ(i);                 }             }              @Override             world void onStartTrackingTouch(SeekBar seekBar) {              }              @Override             world void onStopTrackingTouch(SeekBar seekBar) {              }         });     } }  

more:
– elevation upshot of overlapped view