Department of famous door Android (7) - Control (View)

Department of famous door Android (7) - Control (View) of ZoomControls, Include, VideoView, WebView, RatingBar, Tab, Spinner, Chronometer, ScrollView

Describes the use of various controls in the Android (View)
ZoomControls - Zoom in / out button control
Include - Integrated control
VideoView - video playback controls
WebView - Browser Control
RatingBar - rate control
Tab - Tab Control
Spinner - the drop-down box control
Chronometer - Timer Control
ScrollView - scroll bar controls

1.ZoomControls   The  Demo
zoomcontrols.xml 

  Code
<?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">

    <!--
          Zoom in / out button control
    -->
    <ZoomControls android:id="@+id/zoomControls"
        android:layout_width="wrap_content" android:layout_height="wrap_content"></ZoomControls>

</LinearLayout>

_ZoomControls.java

  Code
package com.webabcd.view;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;
import android.widget.ZoomControls;

public class _ZoomControls extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.zoomcontrols);

        setTitle("ZoomControls");

        ZoomControls zoomControls = (ZoomControls) this.findViewById(R.id.zoomControls);
        // setOnZoomInClickListener() -   Click the Zoom button event response
        zoomControls.setOnZoomInClickListener(new OnClickListener() {
            public void onClick(View v) {
                Toast.makeText(_ZoomControls.this, "  Click the zoom button  ", Toast.LENGTH_SHORT).show();
            }
        });

        // setOnZoomOutClickListener() -   Click the button to respond to events that reduce
        zoomControls.setOnZoomOutClickListener(new OnClickListener() {
            public void onClick(View v) {
                Toast.makeText(_ZoomControls.this, "  Click the Zoom out button  ", Toast.LENGTH_SHORT).show();
            }
        });

    }
}

2.Include   The  Demo
include.xml

  Code
<?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">

    <!--
        include -   Integration of control, the specified   layout   Integration came
            layout -   Specify integration   layout
    -->
    <include android:id="@+id/cell1" layout="@layout/include_1" />
    <include android:id="@+id/cell2" android:layout_width="fill_parent" layout="@layout/include_2" />

</LinearLayout>

include_1.xml

  Code
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:text="TextView01" android:layout_width="wrap_content"
    android:layout_height="wrap_content">
</TextView>

include_2.xml

  Code
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:text="TextView02" android:layout_width="wrap_content"
    android:layout_height="wrap_content">
</TextView>

_Include.java

  Code
package com.webabcd.view;

import android.app.Activity;
import android.os.Bundle;

public class _Include extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.include);

        setTitle("Include");
    }
}

3.VideoView   The  Demo
videoview.xml

  Code
<?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">

    <!--
        VideoView -   Video playback controls
    -->
    <VideoView android:id="@+id/videoView" android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    </VideoView>

</LinearLayout>

_VideoView.java
  Code
package com.webabcd.view;

import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;

public class _VideoView extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.videoview);

        setTitle("VideoView");

        VideoView videoView = (VideoView) findViewById(R.id.videoView);

        //   Specifies the address of the video player
        videoView.setVideoURI(Uri.parse("android.resource://com.webabcd.view/" + R.raw.demo));
        // videoView.setVideoPath();

        //   Setting the player control bar
        videoView.setMediaController(new MediaController(this));
        //   Start playing video
        videoView.start();
    }
}

4.WebView   The  Demo
webview.xml

  Code
<?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">

    <!--
        WebView -   Browser Control  (WebKit   Kernel  )
    -->
    <WebView android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:id="@+id/webView" />

</LinearLayout>

_WebView.java

  Code
package com.webabcd.view;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;

public class _WebView extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.webview);

        setTitle("WebView");

        WebView webView = (WebView) findViewById(R.id.webView);

        //   Configure the browser so that it can support   JavaScript
        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptEnabled(true);

        //   Clear your browser cache
        webView.clearCache(true);
        //   Specify the browser to parse the url address
        webView.loadUrl("http://webabcd.cnblogs.com/");
        //   Specify the browser to parse the html data
        // webView.loadData("<a href='http://webabcd.cnblogs.com/'>webabcd</a>", "text/html", "utf-8");
    }
}

5.RatingBar   The  Demo
ratingbar.xml

  Code
<?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">

    <!--
        RatingBar -   Rated control
            numStars -   The number of stars rating control
            rating -   The value of the current rating
    -->
    <RatingBar android:id="@+id/ratingBar" android:numStars="5"
        android:rating="1.5" android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    </RatingBar>

    <TextView android:id="@+id/textView" android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>

_RatingBar.java

  Code
package com.webabcd.view;

import android.app.Activity;
import android.os.Bundle;
import android.widget.RatingBar;
import android.widget.TextView;

public class _RatingBar extends Activity implements RatingBar.OnRatingBarChangeListener {

    private RatingBar mRatingBar;
    private TextView mTextView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.ratingbar);

        setTitle("RatingBar");

        mTextView = (TextView) findViewById(R.id.textView);
        mRatingBar = (RatingBar) findViewById(R.id.ratingBar);

        // setOnRatingBarChangeListener() -   Score value changes in response to events
        mRatingBar.setOnRatingBarChangeListener(this);
    }

    @Override
    public void onRatingChanged(RatingBar ratingBar, float rating,
            boolean fromUser) {
        mTextView.setText(String.valueOf(rating));
    }
}

6.Tab   The  Demo
tab.xml

  Code
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent">

    <!-- Tab 1   Content   -->
    <TextView android:id="@+id/view1" android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:text="tab1 content" />

    <!-- Tab 2   Content   -->
    <TextView android:id="@+id/view2" android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:text="tab2 content" />

</FrameLayout>

_Tab.java

  Code
package com.webabcd.view;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.widget.TabHost;

//   Tab function to achieve something to inherit   TabActivity
public class _Tab extends TabActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);

        TabHost tabHost = getTabHost();
        LayoutInflater.from(this).inflate(R.layout.tab, tabHost.getTabContentView(), true);

        // Tab 1   Content
        tabHost.addTab(tabHost.newTabSpec("tab1")
                .setIndicator("tab1")
                .setContent(R.id.view1));

        // Tab 2   Content  (  Setting the Tab picture  )
        tabHost.addTab(tabHost.newTabSpec("tab2")
                .setIndicator("tab2", getResources().getDrawable(R.drawable.icon01))
                .setContent(R.id.view2));

        // Tab 3   Content  (  Set the contents of the specified Tab   Activity)
        tabHost.addTab(tabHost.newTabSpec("tab3")
                .setIndicator("tab3")
                .setContent(new Intent(this, _TextView.class)));

    }
}

7.Spinner   The  Demo
spinner.xml

  Code
<?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">

    <TextView android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:id="@+id/textView" />

    <!--
        Spinner -   Drop-down box control
    -->
    <Spinner android:id="@+id/spinner" android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

_Spinner.java

  Code
package com.webabcd.view;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;

public class _Spinner extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.spinner);

        setTitle("Spinner");

        Spinner spinner = (Spinner) findViewById(R.id.spinner);

        //   Set the title text drop-down box control
        spinner.setPrompt("  Please select  ");
        //  Instance of the adapter, specify the display format and data source
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
                this, R.array.colors, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(adapter);

        // setOnItemSelectedListener() -   Drop-down box to select the value of the response to change events
        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> arg0, View arg1,
                    int arg2, long arg3) {
                TextView textView = (TextView)_Spinner.this.findViewById(R.id.textView);
                textView.setText(((TextView)arg1).getText());
            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0) {

            }
        });
    }
}

8.Chronometer   The  Demo
chronometer.xml

  Code
<?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">

    <!--
        Chronometer -   Timer control
    -->
    <Chronometer android:id="@+id/chronometer"
        android:layout_width="wrap_content" android:layout_height="wrap_content" />

    <Button android:id="@+id/btnStart" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:text="  Start time  ">
        <requestFocus />
    </Button>

    <Button android:id="@+id/btnStop" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:text="  Stop the clock  ">
    </Button>

    <Button android:id="@+id/btnReset" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:text="  Timer reset  ">
    </Button>

</LinearLayout>

_Chronometer.java

  Code
package com.webabcd.view;

import android.app.Activity;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Chronometer;

public class _Chronometer extends Activity {

    private Chronometer mChronometer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.chronometer);

        setTitle("Chronometer");

        Button button;

        mChronometer = (Chronometer) findViewById(R.id.chronometer);
        //   Set the timer shows the time format
        mChronometer.setFormat("  Time  :(%s)");

        button = (Button) findViewById(R.id.btnStart);
        button.setOnClickListener(mStartListener);

        button = (Button) findViewById(R.id.btnStop);
        button.setOnClickListener(mStopListener);

        button = (Button) findViewById(R.id.btnReset);
        button.setOnClickListener(mResetListener);
    }

    View.OnClickListener mStartListener = new OnClickListener() {
        public void onClick(View v) {
            //   Start timer
            mChronometer.start();
        }
    };

    View.OnClickListener mStopListener = new OnClickListener() {
        public void onClick(View v) {
            //   Pause timer
            mChronometer.stop();
        }
    };

    View.OnClickListener mResetListener = new OnClickListener() {
        public void onClick(View v) {
            //   Reset the timer, which stops the timer
            mChronometer.setBase(SystemClock.elapsedRealtime());
        }
    };
}

9.ScrollView   The  Demo
scrollview.xml

  Code
<?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">

    <!--
        ScrollView -   Scroll bar control
            scrollbarStyle -   The style of scroll bar
    -->
    <ScrollView android:id="@+id/scrollView"
        android:layout_width="fill_parent" android:layout_height="200px"
        android:scrollbarStyle="outsideOverlay" android:background="@android:drawable/edit_text">
        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:id="@+id/textView" />
    </ScrollView>

</LinearLayout>

_ScrollView.java

  Code
package com.webabcd.view;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class _ScrollView extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.scrollview);

        setTitle("ScrollView");

        TextView textView = (TextView)this.findViewById(R.id.textView);
        textView.setText("a\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na");
    }
}
分类:Mobile 时间:2010-08-26 人气:269
分享到:
blog comments powered by Disqus

相关文章

  • public void testStatementAddBatch () public void testConnCommit () 2011-09-01

    public void testStatementAddBatch() { Connection conn = null; Statement stmt = null; try { conn = getDBConnectionMsSqlBySuperAdmin(); stmt = conn.createStatement(); for(int i = 0; i < 100; i++) { String sql = " sql " + i; stmt.addBatch(sql);

  • jQuery加载XML文档Demo 2012-11-06

    练习一下使用jQuery加载XML文档,参考<jQuery基础教程>6.1.3节 创建三个文件:roster.xml,index.html,script.js.下载jQuery. roster.xml:简化的XMPP联系人模型,只有名称和分组 <?xml version="1.0" encoding="UTF-8"?> <items> <item name='User1'><group>Group1<

  • Dynamically change the screen orientation 2010-08-06

    LANDSCAPE and PORTRAIT Sample Description Activity program control to how the display direction? In Android, the adoption of procedures to change the direction of the screen display must be covered setRequestedOrientation () method, and to obtain the

  • 使用Dom4j解析XML 2015-01-10

    dom4j是一个Java的XML API,类似于jdom,用来读写XML文件的.dom4j是一个非常非常优秀的Java XML API,具有性能优异.功能强大和极端易用使用的特点,同时它也是一个开放源代码的软件,可以在SourceForge上找到它. 对主流的Java XML API进行的性能.功能和易用性的评测,dom4j无论在那个方面都是非常出色的.如今你可以看到越来越多的Java软件都在使用dom4j来读写XML,例如Hibernate,包括sun公司自己的JAXM也用了Dom4j. 使用

  • Log4j.xml Summary 2010-03-29

    Content: 1, Log4J configuration files to learn 2, Log4J Database 3, Log4J package 1, Log4J configuration file to learn: Log4j supports two configuration file formats, one is XML-formatted file, a file is a Java properties (key = value). Here we first

  • JQuery's AJAX cross-domain to solve the problem take xml 2009-07-12

    Problem Description: 1. According to the known url, get url in the id, and then spliced out another url, to get the id corresponding value. For example: Known url: http://video.guoshi.com/play/index/4b6a3c233b4cb.html?peixun=1&start=680000 Get id of:

  • Servlet accept the HTTP request parsing XML data, return XML 2008-05-23

    Servlet to accept submission of project needs over the XML parsing http, the return data. OutputStream output = null; HttpURLConnection conn = null; Document document = null; SAXReader reader = new SAXReader(); URL _url; if (StringUtil.isNotEmpty(xml

  • Write an xml with the DOM approach of the tools 2010-03-28

    Nothing under the recently compiled the application on java dom, dom included in the analytical methods, create, modify and delete operations. Feel should give beginner dom to provide point of reference for students. Writing process in the tools De Y

  • [Reprinted] read xml file on the learning Java 2010-03-29

    Talking about the content of this article is on the Java read xml file in the relevant the content of the article can be divided into three parts, namely, Java classes, xml files Yiji the final output. package com.java.test; import org.w3c.dom.*; imp

  • JQuery's AJAX cross-domain access to solve the problem xml 2010-03-07

    Problem description: 1. According to the known url, get url in the id, and then spliced to another url, to obtain the corresponding value of the id. For example: Known url: http://video.guoshi.com/play/index/4b6a3c233b4cb.html?peixun=1&start=680000 A

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.440 (s). 12 q(s)