Department of famous Gate Android (7) - Controls (View)

分类:Mobile 2010-03-29 来源:CodeWeblog.com 人气:687

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

Author: webabcd

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

1 The Demo, ZoomControls
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  / Zoom 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() -  In response to an event click to enlarge button
        zoomControls.setOnZoomInClickListener(new OnClickListener() {
            public void onClick(View v) {
                Toast.makeText(_ZoomControls.this, " Click the zoom in button  ", Toast.LENGTH_SHORT).show();
            }
        });

        // setOnZoomOutClickListener() -  In response to the click event of the zoom
        zoomControls.setOnZoomOutClickListener(new OnClickListener() {
            public void onClick(View v) {
                Toast.makeText(_ZoomControls.this, " Click the zoom out button  ", Toast.LENGTH_SHORT).show();
            }
        });

    }
}

2 The Demo, Include
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 -  Consolidated control, adds the specified layout consolidation come in
            layout -  Specifies the layout needs to be consolidated
    -->
    <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 And the Demo VideoView
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 -  The 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 playback
        videoView.setVideoURI(Uri.parse("android.resource://com.webabcd.view/" + R.raw.demo));
        // videoView.setVideoPath();

        //  Set the player's control bars
        videoView.setMediaController(new MediaController(this));
        //  Start playing the video
        videoView.start();
    }
}

4 The Demo, WebView
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 -  The 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 your browser to support JavaScript
        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptEnabled(true);

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

5 The Demo, RatingBar
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 -  Score control
            numStars -  Ratings control the number of stars
            rating -  The value of the current ratings
    -->
    <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() -  In response to a change in rating value of events
        mRatingBar.setOnRatingBarChangeListener(this);
    }

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

6 And the Demo Tab
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  The contents of the  -->
    <TextView android:id="@+id/view1" android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:text="tab1 content" />

    <!-- Tab 2  The contents of the  -->
    <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;

//  Implementation inheritance Tab functionality to 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  The contents of the
        tabHost.addTab(tabHost.newTabSpec("tab1")
                .setIndicator("tab1")
                .setContent(R.id.view1));

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

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

    }
}

7 , Spinner's 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 -  The 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);

        //  Setting the drop-down box control's header text
        spinner.setPrompt(" Please select the  ");
        //  Instantiate the adapter, specify the display format of the 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() -  In response to the drop-down box of the selected value 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 The Chronometer, 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 timing  ">
        <requestFocus />
    </Button>

    <Button android:id="@+id/btnStop" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:text=" To stop the chronograph  ">
    </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 a timer displays the time format
        mChronometer.setFormat(" Timing:  (%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 the 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 And the Demo ScrollView
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 -  The scroll bar control
            scrollbarStyle -  The scroll bar's style
    -->
    <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");
    }
}
分享到:
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); } stm

  • 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:

  • 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 Ye I f

  • [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. Output: Root elements: book book node in the cha ...

  • 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 Ac

  • Read xml dom4j examples of applications 2010-03-16

    Recent study open source software "LAN chat tool Net-C", project home page for the http://dgtalize.com/products/netc, There are paragraphs of the code is to read and write xml files with dom4j, and I use the newer dom4j2.0 rewrite the code ...

  • Android (c) of the data storage of the XML parsing technology 1 2010-10-09

    Android today continue to study the use of the XML Pull parsing of XML technology to parse and create the file. Since tomorrow to rest, better time, so I will not summarize the SAX parsing yesterday in this wrap up. A, SAX parsing technology Sax uses even

  • Android (c) of the data storage of XML parsing techniques 2 2010-10-09

    Second, Pull parsing technology Sax Pull parsing technology and analytical techniques on the same principle, but Sax resolution than simple analysis of their speed and take up less resources. Android internal use XML parsing technology is Pull, Android de

  • java parsing of XML documents. nodes increases. deletions Summary 2010-10-11

    package test; import java.io.IOException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.Transformer; import javax.xml.trans

  • Android中使用pull解析器操作xml文件的解决办法 2013-10-01

    本篇文章介绍了,在Android中使用pull解析器操作xml文件的解决办法。需要的朋友参考下 一、使用Pull解析器读取XML文件 除了可以使用SAX或DOM解析XML文件之外,大家也可以使用Android内置的Pull解析器解析XML文件。 Pull解析器是一个开源的java项目,既可以用于android,也可以用于JavaEE。如果用在javaEE需要把其jar文件放入类路径中,因为Android已经集成进了Pull解析器,所以无需添加任何jar文件。android系统本身使用到的各种xm

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

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

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

processed in 0.241 (s). 14 q(s)