Star Wars Crawl with SeekBar

We saw a SeekBar and a SeekBar.OnSeekBarChangeListener here.

The background color of the RelativeLayout is black; the background color of the three TextViews is transparent. The text is split into three TextViews because the content of only the first two are centered with android:gravity="center_horizontal". To make the text justified on both sides, we could have used a WebView instead of a TextView. The WebView would display text formatted with the HTML property text-align: justify.

The three TextViews are held in a vertical LinearLayout. The listener moves the TextViews up and down by decreasing and increasing the amount of the LinearLayout’s top padding.

On Mac, type fn-control-F12 to rotate the Android emulator to landscape orientation. See Crawler to move the crawl without a SeekBar.

Source code in Crawl.zip

  1. MainActivity.java. linearLayout had to be final to allow us to mention it in a method of the inner class.
  2. activity_main.xml.
  3. strings.xml. \n is the newline character, \u0027 is the Unicode apostrophe’, and \u2026 is the Unicode ellipses…
  4. AndroidManifest.xml. The activity element has the attribute android:screenOrientation="landscape".
  5. build.gradle (Module: app)

SeekBars in ApiDemos

This app was inspired by the following demo.

  1. Views → Rotating Button
    TX and TY set the horizontal and vertical translation. SX and SY set the horizontal and vertical scale. X, Y, and Z set the rotations around the X, Y, and Z axes. This demo should have used an ImageView instead of a Button.
    1. ApiDemos/src/com/example/android/apis/view/RotatingButton.java
      Class com.example.android.apis.view.RotatingButton is a subclass of class Activity. Its onCreate method installs seven SeekBar.OnSeekBarChangeListeners into the seven SeekBars.
    2. ApiDemos/res/layout/rotating_view.xml
      creates a vertical LinearLayout containing three horizontal LinearLayouts and a Button. The horizontal LinearLayouts contain a total of seven SeekBars.
    3. ApiDemos/AndroidManifest.xml lists class RotatingButton on lines 2474–2479.

Things to try

  1. The SeekBar.OnSeekBarChangeListener is supposed to change only the top padding of the vertical LinearLayout. To ensure that it does not change the other three paddings, change
                    linearLayout.setPadding(0, 1110 - progress, 0, 0);   //left, top, right, bottom
    
    to
                    linearLayout.setPadding(
                        linearLayout.getPaddingLeft(),
                        1110 - progress,
                        linearLayout.getPaddingRight(),
                        linearLayout.getPaddingBottom()
                    );