Android Implementation in List List Display Semitransparent Small Form Effect Control Usage Detailed Explanation

  • 2021-07-26 08:56:27
  • OfStack

This article illustrates the use of Android controls to display the effect of translucent small forms in the list List. Share it for your reference, as follows:

Android in the list of List display translucent small form effect of the control, more or less directly on the code, to say all in the comments:


import com.hiapk.market.R;
import android.content.Context;
import android.graphics.PixelFormat;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import android.widget.TextView;
/**
 *  A widget that displays a translucent prompt box in the middle of the window 
 *  Usage: 1. new 2. showPrevLetter(String prevLetter)
 * @author LL
 *
 */
public class PrevLetterDialog {
  // Delay time for form disappearance 
  private static final int DELAYED_HIDEN = 500;
  //  Realization Runnable Class of interface 
  private RemoveWindow mRemoveWindow = new RemoveWindow();
  // In Handler It can realize the right UI Modification of threads 
  private Handler mHandler;
  // Form Manager 
  private WindowManager mWindowManager;
  // Displays a translucent font box in the middle of the form 
  private TextView mDialogText;
  // Is it being displayed 
  private boolean mShowing;
  // Are you ready to display 
  private boolean mReady;
  // Characters displayed in the form 
  private char mPrevLetter = Character.MIN_VALUE;
  /**
   *  Note: context1 Be sure to be visible UI Passed in getContext() Obtain, otherwise an exception will be thrown. 
   * @param context
   */
  public PrevLetterDialog(Context context) {
    // Get the form manager 
    mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    // Get the founder of the cloth department 
    LayoutInflater inflate = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    // Get TextView
    mDialogText = (TextView) inflate.inflate(R.layout.list_position, null);
    // Set TextView Is visible 
    mDialogText.setVisibility(View.INVISIBLE);
    // Pass handler Put mDialogText Show it 
    mHandler = new Handler();
    // To use post Can be called in multiple threads UI Thread and change 
    mHandler.post(new Runnable() {
      public void run() {
        mReady = true;
        // Layout parameters of the form 
        WindowManager.LayoutParams lp = new WindowManager.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.TYPE_APPLICATION,
            WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
            PixelFormat.TRANSLUCENT);
        // Put TextView Add to the form 
        mWindowManager.addView(mDialogText, lp);
      }
    });
  }
  // Setting Visibility 
  public void setmReady(boolean mReady) {
    this.mReady = mReady;
  }
  /**
   * 1 Be generally used in onScroll Method , Parameter is a string, cannot be empty, will take the first 1 Character display 
   * @param prevLetter
   */
  public void showPrevLetter(String prevLetter) {
    if (!mReady) {
      return;
    }
    char firstLetter = prevLetter.charAt(0);
    if (!mShowing && firstLetter != mPrevLetter) {
      mShowing = true;
      mDialogText.setVisibility(View.VISIBLE);
    }
    // Set TextView Displayed fonts 
    mDialogText.setText(((Character) firstLetter).toString());
    // Remove mRemoveWindow Realized Runnable Interface class 
    mHandler.removeCallbacks(mRemoveWindow);
    // Add mRemoveWindow Realized Runnable Interface class, and set delay 
    mHandler.postDelayed(mRemoveWindow, DELAYED_HIDEN);
    mPrevLetter = firstLetter;
  }
  /**
   *  Realization Runnable Class of interface 
   */
  private final class RemoveWindow implements Runnable {
    public void run() {
      removeWindow();
    }
  }
  private void removeWindow() {
    if (mShowing) {
      mShowing = false;
      mDialogText.setVisibility(View.INVISIBLE);
    }
  }
}

The following is the xml file:


<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
  android:textSize="50sp"
  android:textColor="@color/band_common_content"
  android:background="@drawable/common_list_title"
  android:minWidth="70dip"
  android:layout_height="wrap_content"
  android:padding="5dip"
  android:gravity="center"
/>

For more readers interested in Android related contents, please check the topics on this site: "Summary of activity Operation Skills for Android Programming", "Summary of Android File Operation Skills", "Summary of SD Card Operation Methods for Android Programming Development", "Introduction and Advanced Tutorial for Android Development", "Summary of Android Resource Operation Skills", "Summary of View Skills for Android View" and "Summary of Android Control Usage"

I hope this article is helpful to everyone's Android programming.


Related articles: