Android TV achieves color bar scrolling, androidtv

Source: Internet
Author: User

Android TV achieves color bar scrolling, androidtv

Directly paste the Code:

ColorView. java

Package com. xxx. demo; import android. content. context; import android. graphics. canvas; import android. graphics. color; import android. graphics. paint; import android. util. attributeSet; import android. util. log; import android. view. view; import android. view. windowManager;/*** color effect view1 */public class ColorView extends View {int width; int height; Paint p; int I = 0; int all = 256*5; // color value change int exteraLength = 1; Context context = null; int j = 0; int mLength = 0; // The addition value of j for each re-painting public ColorView (Context context) {super (context ); this. context = context; WindowManager wm = (WindowManager) getContext (). getSystemService (Context. WINDOW_SERVICE); width = wm. getdefadisplay display (). getWidth (); height = wm. getdefadisplay display (). getHeight (); // determines whether it is a standard height System. out. println ("width =" + width); System. out. println ("heig Ht = "+ height); p = new Paint (); if (all> = width) {mLength = 80;} else {mLength = 30; exteraLength = (int) math. ceil (1.0 * all/(width-all);} this. setFocusable (true); this. setKeepScreenOn (true); I = 0;} public ColorView (Context context, AttributeSet attributeSet) {super (context, attributeSet); this. context = context; WindowManager wm = (WindowManager) getContext (). getSystemService (Con Text. WINDOW_SERVICE); width = wm. getdefadisplay display (). getWidth (); height = wm. getdefadisplay display (). getHeight (); System. out. println ("width =" + width); System. out. println ("height =" + height); p = new Paint (); p. setAntiAlias (true); p. setStyle (Paint. style. FILL); if (all> = width) {mLength = 80;} else {mLength = 30; exteraLength = (int) Math. ceil (1.0 * all/(width-all);} this. setFocusable (true); This. setKeepScreenOn (true); I = 0 ;}@ Override protected void onDraw (Canvas canvas) {super. onDraw (canvas); if (j> all) {// indicates the end. Still need to be drawn, otherwise the interface will become black myDraw (canvas); System. out. println ("end"); return;} myDraw (canvas); j + = mLength; // change the value of j to invalidate (); // redraw the view after onDraw, subjective animation} public void myDraw (Canvas canvas) {// create a paint brush // red (R: 255G: 0 B: 0) // orange (R: 255G: 156 B: 0) // yellow (R: 255G: 255 B: 0) // Green (R: 0G: 255 B: 0) // blue (R: G: 255 B: 255) // blue (R: 0G: 0 B: 255) // purple (R: 255G: B: 255) system. out. println ("canvas"); Log. I ("Canvas: X:", "complexdraw"); I = 0; while (I <= j) {if (I <= 255) {p. setColor (Color. rgb (255, I, 0);} else if (I >=256 & I <= 511) {p. setColor (Color. rgb (511-I, 255, 0);} else if (I >= 512 & I <= 767) {p. setColor (Color. rgb (0,255, I-512);} else if (I >=768 & I <= 1023) {p. setColor (Color. rgb (0, 1023-I, 255);} else if (I >= 1024 & I <= 1279) {p. setColor (Color. rgb (I-1024, 0,255);} // processing different resolutions, resulting in differences in drawing, evenly divided color values, screen width 12 80. The color value range is also 1280. For Xiaomi TV, the screen width is 1920. if the screen width is exceeded, it needs to be evenly divided. The following is the processing method if (exteraLength! = 1) {if (I % exteraLength = exteraLength-1) {System. out. println ("exteraLength =" + exteraLength); System. out. println ("current =" + I); canvas. drawLine (I + I/exteraLength, 0, I + I/exteraLength, height, p); // draw a canvas. drawLine (I + I/exteraLength + 1, 0, I + I/exteraLength + 1, height, p);} else {System. out. println ("exteraLength = 1 --------->" + exteraLength); System. out. println ("current =" + I); canvas. drawLine (I + I/exteraLength, 0, I + I/exteraLength, height, p) ;}} else {canvas. drawLine (I, 0, I, height, p) ;} I ++ ;}}}

MainActivity. java

public class MainActivity extends Activity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        requestWindowFeature(Window.FEATURE_NO_TITLE);        setContentView(R.layout.activity_color);    }}

Activity_color.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"              android:orientation="vertical"              android:layout_width="fill_parent"              android:layout_height="fill_parent">    <com.xxx.demo.ColorView            android:id="@+id/colorView"            android:layout_width="fill_parent"            android:layout_height="fill_parent"            /></LinearLayout>

In the onDraw () method of the custom view, the invalidate () method can be called to achieve the effect similar to moving a ball ..


How can I scroll part of the android xml layout out of the screen?

Try writing the height of the control in ScrollView

In android, how does one click the button to scroll the image?

First, viewpager and gallery should not make such errors;
Secondly, although gallery has expired, it can still be used. We recommend that you use it because the two replacement schemes mentioned in the API are used to achieve this effect, it is not as convenient as gallery;
This effect is very simple. horizontal layout: buttons + gallery + buttons;
You can use gallery on your own. There are a lot of materials;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.