編輯:Android開發實例
當您TextView中的字數太多,不足以在屏幕上完整顯示時,如何使一個TextView用ScrollView滾動顯示呢?
下面我舉一個簡單的例子:
代碼:
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.IOException;
- import org.apache.http.util.EncodingUtils;
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.ScrollView;
- import android.widget.TextView;
- import android.widget.Toast;
- public class pass extends Activity {
- /** Called when the activity is first created. */
- final String TEXT_ENCODING = "UTF-8";
- ScrollView sv;
- TextView tv;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.passdialog);
- sv=(ScrollView)findViewById(R.id.sv);
- tv=(TextView)findViewById(R.id.txtView);
- tv.setText("mmmmmmmmmmmmmmmmmmmmm" +
- "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" +
- "llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll+
- "gggggggggggggggggggggggggggggggggggggggggggggggggg" +
- "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv," +
- "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq" +
- "hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh");
- }
- }
- passdialog.xml:
- <?xml version="1.0" encoding="utf-8"?>
- <AbsoluteLayout
- android:id="@+id/widget38"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- xmlns:android="http://schemas.android.com/apk/res/android"
- >
- <LinearLayout
- android:id="@+id/widget32"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_x="0px"
- android:layout_y="0px"
- >
- </LinearLayout>
- <ScrollView
- android:id="@+id/sv"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_x="0px"
- android:layout_y="20px"
- >
- <TextView
- android:id="@+id/txtView"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:textSize="22sp"
- android:gravity="center_vertical"
- >
- </TextView>
- </ScrollView>
- </AbsoluteLayout>
一.Gallery的簡介 Gallery(畫廊)是一個鎖定中心條目並且擁有水平滾動列表的視圖,一般用來浏覽圖片,並且可以響應事件顯示信息。Gallery還可以和I
使用樣式文件,在values 目錄下新建styles.xml文件,編寫如下代碼: 代碼如下: Code highlighting produced by Acti
之前曾經在網上看到Android仿QQ空間底部菜單的Demo,發現這個Demo有很多Bug,布局用了很多神秘數字。於是研究了一下QQ空間底部菜單的實現,自己寫了一
JSON代表JavaScript對象符號。它是一個獨立的數據交換格式,是XML的最佳替代品。本章介紹了如何解析JSON文件,並從中提取所需的信息。Android提供了四個