編輯:關於Android編程
package zy.Scroller; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import org.apache.http.util.EncodingUtils; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ScrollView; import android.widget.TextView; import android.widget.Toast; public class main extends Activity { /** Called when the activity is first created. */ final public String DEV_FILE = "/data/data/zy.Scroller/aaa.txt";// 測試文件 final String TEXT_ENCODING = "UTF-8"; ScrollView sv; TextView tv; public Button test; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); sv = (ScrollView) findViewById(R.id.sv); tv = (TextView) findViewById(R.id.txtView); String str; str = getinfo(DEV_FILE); String[] x; x = str.split("/r"); tv.setText(x[0]); int i; for (i = 1; i <= x.length - 1; i++) { tv.append(x[i]); } test = (Button) findViewById(R.id.test); test.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub sv.scrollTo(0, 2222); DisplayToast(sv.getScrollY() + ""); } }); } protected void onScrollChanged(int l, int t, int oldl, int oldt) { DisplayToast("123"); } public String getinfo(String path) { File file; String str = ""; FileInputStream in; try { // 打開文件file的InputStream file = new File(path); in = new FileInputStream(file); // 將文件內容全部讀入到byte數組 int length = (int) file.length(); byte[] temp = new byte[length]; in.read(temp, 0, length); // 將byte數組用UTF-8編碼並存入display字符串中 str = EncodingUtils.getString(temp, TEXT_ENCODING); // 關閉文件file的InputStream in.close(); } catch (IOException e) { DisplayToast(e.toString()); } return str; } public void DisplayToast(String str) { Toast.makeText(this, str, Toast.LENGTH_SHORT).show(); } }
大致分是這幾步: (1)新建Android工程: HelloJni.java代碼 package com.panpass.main; public c
熟悉Android的朋友們都知道,不管是微博客戶端還是新聞客戶端,都離不開列表組件,可以說列表組件是Android數據展現方面最重要的組件,我們今天就要講一講
引言Android在3.0中引入了Fragments的概念,其目的是用在大屏幕設備上–例如平板電腦上,支持更加動態和靈活的UI設計。平板電腦的屏幕要比手機的大
Android 動態改變布局