Android Notes-Threads

Source: Internet
Author: User

Java:

Package com.example.test_ui_thread01;

Import android.support.v7.app.AppCompatActivity;
Import Android.os.Bundle;
Import Android.view.View;
Import android.view.animation.TranslateAnimation;
Import Android.widget.Button;

public class Mainactivity extends Appcompatactivity {

@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
Add an animation action to Button1
Button button1 = (button) Findviewbyid (R.id.button1);
translateanimation animation = new Translateanimation (0,150,0,0);
Animation.setrepeatcount (30);
Animation.setduration (2000);
Button1.setanimation (animation);

Button button2 = (button) Findviewbyid (R.id.button2);
Button2.setonclicklistener (New View.onclicklistener () {
@Override
public void OnClick (view view) {
New Thread (New Runnable () {
@Override
public void Run () {
try {
Thread.Sleep (5000);
} catch (Interruptedexception e) {
E.printstacktrace ();
}
}
}). Start ();


}
});
}
}
Xml:
<?xml version= "1.0" encoding= "Utf-8"?>
<relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Xmlns:tools= "Http://schemas.android.com/tools"
Android:id= "@+id/activity_main"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:paddingbottom= "@dimen/activity_vertical_margin"
android:paddingleft= "@dimen/activity_horizontal_margin"
android:paddingright= "@dimen/activity_horizontal_margin"
android:paddingtop= "@dimen/activity_vertical_margin"
Tools:context= "COM.EXAMPLE.TEST_UI_THREAD01. Mainactivity ">

<textview
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:text= "Hello world!"
Android:id= "@+id/textview"/>

<button
android:text= "button"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:layout_below= "@+id/textview"
Android:layout_alignparentleft= "true"
Android:layout_alignparentstart= "true"
android:layout_marginleft= "29DP"
Android:layout_marginstart= "29DP"
android:layout_margintop= "97DP"
Android:id= "@+id/button1"/>

<button
android:text= "button"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:layout_below= "@+id/button"
android:layout_alignleft= "@+id/button"
Android:layout_alignstart= "@+id/button"
android:layout_marginleft= "18DP"
Android:layout_marginstart= "18DP"
android:layout_margintop= "81DP"
Android:id= "@+id/button2"/>
</RelativeLayout>

Android Notes-Threads

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.