欢迎页面:WelcomActivity
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
public class WelcomActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.welcome);
new Thread(){
public void run() {
try {
Thread.sleep(1500);
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
finish();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}.start();
}
}
主页面:MainActivity
import java.util.ArrayList;
import java.util.List;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.ImageView;
import com.madeLi.hufuman.fragment.BianmaActivity;
import com.madeLi.hufuman.fragment.JianjieActivity;
import com.madeLi.hufuman.fragment.YasuoActivity;
public class MainActivity extends FragmentActivity implements OnClickListener {
Button buttonOne;
Button buttonTwo;
Button buttonThree;
ViewPager mViewPager;
List<Fragment> fragmentList;
BianmaActivity oneFragment;
YasuoActivity twoFragment;
JianjieActivity threeFragment;
ImageView imageviewOvertab;
int screenWidth;
int currenttab = -1;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonOne = (Button) findViewById(R.id.btn_one);
buttonTwo = (Button) findViewById(R.id.btn_two);
buttonThree = (Button) findViewById(R.id.btn_three);
buttonOne.setOnClickListener(this);
buttonTwo.setOnClickListener(this);
buttonThree.setOnClickListener(this);
mViewPager = (ViewPager) findViewById(R.id.viewpager);
fragmentList = new ArrayList<Fragment>();
oneFragment = new BianmaActivity();
twoFragment = new YasuoActivity();
threeFragment = new JianjieActivity();
fragmentList.add(oneFragment);
fragmentList.add(twoFragment);
fragmentList.add(threeFragment);
screenWidth = getResources().getDisplayMetrics().widthPixels;
buttonTwo.measure(0, 0);
imageviewOvertab = (ImageView) findViewById(R.id.imgv_overtab);
mViewPager.setAdapter(new MyFrageStatePagerAdapter(
getSupportFragmentManager()));
}
/**
* 定义自己的ViewPager适配器。 也可以使用FragmentPagerAdapter。关于这两者之间的区别,可以自己去搜一下。
*/
class MyFrageStatePagerAdapter extends FragmentStatePagerAdapter {
public MyFrageStatePagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
return fragmentList.get(position);
}
@Override
public int getCount() {
return fragmentList.size();
}
/**
* 每次更新完成ViewPager的内容后,调用该接口,此处复写主要是为了让导航按钮上层的覆盖层能够动态的移动
*/
@Override
public void finishUpdate(ViewGroup container) {
super.finishUpdate(container);// 这句话要放在最前面,否则会报错
// 获取当前的视图是位于ViewGroup的第几个位置,用来更新对应的覆盖层所在的位置
int currentItem = mViewPager.getCurrentItem();
if (currentItem == currenttab) {
return;
}
imageMove(mViewPager.getCurrentItem());
currenttab = mViewPager.getCurrentItem();
}
}
/**
* 移动覆盖层图片 初始化动画
*
* @param moveToTab
* 目标Tab,也就是要移动到的导航选项按钮的位置 第一个导航按钮对应0,第二个对应1,以此类推
*/
private void imageMove(int moveToTab) {
switch (moveToTab) {
case 0:
initAnimator(buttonOne);
break;
case 1:
initAnimator(buttonTwo);
break;
case 2:
initAnimator(buttonThree);
break;
default:
break;
}
anim.start();
int startPosition = 0;
int movetoPosition = 0;
startPosition = (currenttab * (screenWidth / 3)) + (((screenWidth / 3) - dip2px(this,80)) / 2) - dip2px(this,10);
movetoPosition = moveToTab * (screenWidth / 3) + (((screenWidth / 3) - dip2px(this,80)) / 2) - dip2px(this,10);
// 平移动画
TranslateAnimation translateAnimation = new TranslateAnimation(
startPosition, movetoPosition, 0, 0);
translateAnimation.setFillAfter(true);
translateAnimation.setDuration(200);
imageviewOvertab.startAnimation(translateAnimation);
}
public static int dip2px(Context context,float dpValue) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (dpValue * scale + 0.5f);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_one:
changeView(0);
break;
case R.id.btn_two:
changeView(1);
break;
case R.id.btn_three:
changeView(2);
break;
default:
break;
}
}
// 手动设置ViewPager要显示的视图
private void changeView(int desTab) {
mViewPager.setCurrentItem(desTab, true);
}
private AnimatorSet anim;
private void initAnimator(View view) {
ObjectAnimator anim1 = ObjectAnimator.ofFloat(view, "scaleX", 1f, 0.3f);
ObjectAnimator anim3 = ObjectAnimator.ofFloat(view, "scaleY", 1f, 0.3f);
ObjectAnimator anim2 = ObjectAnimator.ofFloat(view, "scaleX", 0.3f, 1f);
ObjectAnimator anim4 = ObjectAnimator.ofFloat(view, "scaleY", 0.3f, 1f);
ObjectAnimator anim11 = ObjectAnimator
.ofFloat(view, "scaleX", 1f, 0.8f);
ObjectAnimator anim33 = ObjectAnimator
.ofFloat(view, "scaleY", 1f, 0.8f);
ObjectAnimator anim22 = ObjectAnimator
.ofFloat(view, "scaleX", 0.8f, 1f);
ObjectAnimator anim44 = ObjectAnimator
.ofFloat(view, "scaleY", 0.8f, 1f);
anim = new AnimatorSet();
anim.play(anim1).with(anim3);
anim.play(anim2).with(anim4);
anim.play(anim2).after(anim1);
anim.play(anim11).with(anim33);
anim.play(anim22).with(anim44);
anim.play(anim22).after(anim11);
anim.play(anim11).after(anim2);
anim.setDuration(100);
}
}
三个Fragment的子页面:
页面一: BianmaActivity
import java.io.File;
import java.io.FileInputStream;
import java.io.RandomAccessFile;
import org.apache.http.util.EncodingUtils;
import android.os.Bundle;
import android.os.Environment;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.madeLi.BianmaYima.ZhuanHuaBianMa;
import com.madeLi.hufuman.R;
public class BianmaActivity extends Fragment{
ZhuanHuaBianMa zMa = new ZhuanHuaBianMa();
private View carView;
private EditText editText1;
private Button button1,souceBianmaButton,panduanButton;
String filePath = Environment.getExternalStorageDirectory() + "/save/";
String fileName = "souce.txt";
String fileNameCode = "code.txt";
String fileNameDeCode = "decode.txt";
private TextView bianmaTextview,panduanTextview;
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
// TODO Auto-generated method stub
carView = inflater.inflate(R.layout.bianma, container, false);
initView();
return carView;
}
private void initView() {
editText1 = (EditText) carView.findViewById(R.id.editText1);
button1 = (Button) carView.findViewById(R.id.button1);
souceBianmaButton = (Button) carView.findViewById(R.id.bianmaButton);
bianmaTextview = (TextView)carView.findViewById(R.id.soucewenjianbianma);
panduanButton = (Button)carView.findViewById(R.id.panduanButton);
panduanTextview = (TextView)carView.findViewById(R.id.panduanTextView);
button1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
writeTxtToFile(editText1.getText().toString().trim(), filePath, fileName);
zMa.setString(readDataFromSD(fileName));
writeTxtToFile(zMa.getString(), filePath, fileNameCode);
}
});
souceBianmaButton.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
zMa.setString(readDataFromSD(fileName));
writeTxtToFile(zMa.getString(), filePath, fileNameCode);
bianmaTextview.setText(zMa.getBianmaString());
zMa.setS(readDataFromSD(fileNameCode));
writeTxtToFile(zMa.getYimaString(), filePath, fileNameDeCode);
}
});
panduanButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
panduanTextview.setText(zMa.getSouceIsDecode(readDataFromSD(fileName), readDataFromSD(fileNameDeCode)));
}
});
}
// 将字符串写入到文本文件中
public void writeTxtToFile(String strcontent, String filePath, String fileName) {
// 生成文件夹之后,再生成文件,不然会出错
makeFilePath(filePath, fileName);
String strFilePath = filePath + fileName;
// 每次写入时,都换行写
String strContent = strcontent ;
try {
File file = new File(strFilePath);
if (!file.exists()) {
Log.d("TestFile", "Create the file:" + strFilePath);
file.getParentFile().mkdirs();
file.createNewFile();
}
file.delete();
RandomAccessFile raf = new RandomAccessFile(file, "rw");
raf.seek(file.length());
raf.write(strContent.getBytes());
raf.close();
} catch (Exception e) {
e.printStackTrace();
}
}
// 生成文件
public File makeFilePath(String filePath, String fileName) {
File file = null;
makeRootDirectory(filePath);
try {
file = new File(filePath + fileName);
if (!file.exists()) {
file.createNewFile();
}
} catch (Exception e) {
e.printStackTrace();
}
return file;
}
// 生成文件夹
public static void makeRootDirectory(String filePath) {
File file = null;
try {
file = new File(filePath);
if (!file.exists()) {
file.mkdir();
}
} catch (Exception e) {
e.printStackTrace();
}
}
public String readDataFromSD(String str){
String string = "";
try{
/* 创建File对象,确定需要读取文件的信息 */
File file = new File(Environment.getExternalStorageDirectory()+ "/save/",str);
/* FileInputSteam 输入流的对象, */
FileInputStream fis = new FileInputStream(file);
/* 准备一个字节数组用户装即将读取的数据 */
byte[] buffer = new byte[fis.available()];
/* 开始进行文件的读取 */
fis.read(buffer);
/* 关闭流 */
fis.close();
/* 将字节数组转换成字符创, 并转换编码的格式 */
string = EncodingUtils.getString(buffer, "UTF-8");
}catch(Exception ex){
}
return string;
}
}
页面2:JianjieActivity
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.madeLi.hufuman.R;
public class JianjieActivity extends Fragment{
private View carView;
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
// TODO Auto-generated method stub
carView = inflater.inflate(R.layout.jianjie, container, false);
return carView;
}
}
页面3: YasuoActivity
import java.io.File;
import java.io.FileInputStream;
import java.io.RandomAccessFile;
import org.apache.http.util.EncodingUtils;
import android.os.Bundle;
import android.os.Environment;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.madeLi.hufuman.R;
public class YasuoActivity extends Fragment{
private View carView;
private Button codeButton,souceButton,decodeButton;
String filePath = Environment.getExternalStorageDirectory() + "/save/";
String fileName = "souce.txt";
String fileNameCode = "code.txt";
String fileNameDeCode = "decode.txt";
private TextView souceTextview,codeTextview,decodeTextview;
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
// TODO Auto-generated method stub
carView = inflater.inflate(R.layout.yasuo, container, false);
initView();
return carView;
}
private void initView() {
decodeButton = (Button) carView.findViewById(R.id.decodeButton);
souceButton = (Button) carView.findViewById(R.id.souceButton);
decodeTextview = (TextView)carView.findViewById(R.id.decodeTextView);
codeButton = (Button)carView.findViewById(R.id.codeButton);
codeTextview = (TextView)carView.findViewById(R.id.codeTextview);
souceTextview = (TextView)carView.findViewById(R.id.souceTextView);
codeButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
codeTextview.setText(readDataFromSD(fileNameCode));
}
});
decodeButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
decodeTextview.setText(readDataFromSD(fileNameDeCode));
}
});
souceButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
souceTextview.setText(readDataFromSD(fileName));
}
});
}
// 将字符串写入到文本文件中
public void writeTxtToFile(String strcontent, String filePath, String fileName) {
// 生成文件夹之后,再生成文件,不然会出错
makeFilePath(filePath, fileName);
String strFilePath = filePath + fileName;
// 每次写入时,都换行写
String strContent = strcontent ;
try {
File file = new File(strFilePath);
if (!file.exists()) {
Log.d("TestFile", "Create the file:" + strFilePath);
file.getParentFile().mkdirs();
file.createNewFile();
}
file.delete();
RandomAccessFile raf = new RandomAccessFile(file, "rw");
raf.seek(file.length());
raf.write(strContent.getBytes());
raf.close();
} catch (Exception e) {
e.printStackTrace();
}
}
// 生成文件
public File makeFilePath(String filePath, String fileName) {
File file = null;
makeRootDirectory(filePath);
try {
file = new File(filePath + fileName);
if (!file.exists()) {
file.createNewFile();
}
} catch (Exception e) {
e.printStackTrace();
}
return file;
}
// 生成文件夹
public static void makeRootDirectory(String filePath) {
File file = null;
try {
file = new File(filePath);
if (!file.exists()) {
file.mkdir();
}
} catch (Exception e) {
e.printStackTrace();
}
}
public String readDataFromSD(String str){
String string = "";
try{
/* 创建File对象,确定需要读取文件的信息 */
File file = new File(Environment.getExternalStorageDirectory()+ "/save/",str);
/* FileInputSteam 输入流的对象, */
FileInputStream fis = new FileInputStream(file);
/* 准备一个字节数组用户装即将读取的数据 */
byte[] buffer = new byte[fis.available()];
/* 开始进行文件的读取 */
fis.read(buffer);
/* 关闭流 */
fis.close();
/* 将字节数组转换成字符创, 并转换编码的格式 */
string = EncodingUtils.getString(buffer, "UTF-8");
}catch(Exception ex){
}
return string;
}
}
Huffman编码译码,及其哈夫曼树的创建,和对字符出现的个数和不同字符的统计:
class HuffmanNode{
char data;
int weight;
int parent,Lchild,Rchild;
}
class HufumanTree{
public HuffmanNode[] node;
public int m;
HufumanTree(int m){
this.m = m;
this.node = new HuffmanNode[2*m];
for (int i = 1; i <= 2*m-1 ; i++) {
//初始化创建的每一个对象数组
node[i] = new HuffmanNode();
}
}
}
class HFbianma{
public HufumanTree CrtHafushu(char data[],int weight[],int n){
HufumanTree hTree = new HufumanTree(n);
for (int i = 1; i <= 2*n-1 ; i++) {
//初始化哈夫曼树
hTree.node[i].Lchild = 0;
hTree.node[i].Rchild = 0;
hTree.node[i].parent = 0;
if(i<=n){
hTree.node[i].data = data[i];
hTree.node[i].weight = weight[i];
}
}
for(int i=n+1; i<=2*n-1;i++){
int x1 = 0; //保存最小的结点下标
int x2 = 0; //保存次小的结点下标
int m1 = 100000;
int m2 = 100000;
int temp ;
for(int j=1; j<=i-1;j++){
if(hTree.node[j].weight < m1 && hTree.node[j].parent == 0){
m2 = m1;
x2 = x1;
m1 = hTree.node[j].weight;
x1 = j;
}
else if(hTree.node[j].weight < m2 && hTree.node[j].parent == 0){
m2 = hTree.node[j].weight;
x2 = j;
}
}
if(x1>x2){
temp = x1;
x1 = x2;
x2 = temp;
}
hTree.node[i].weight = hTree.node[x1].weight+hTree.node[x2].weight;
hTree.node[i].Lchild = x1;
hTree.node[i].Rchild = x2;
hTree.node[x1].parent = i;
hTree.node[x2].parent = i;
}
return hTree;
}
public String[] BianmaHuffman(HufumanTree hTree,int n){
String[] str = new String[n+1];
for (int i = 1; i <= n; i++) {
str[i] = "";
}
int c,p;
for (int i = 1; i <= n; i++) {
String string = "";
c = i;p = hTree.node[i].parent;
while(p!=0){
if(hTree.node[p].Lchild == c)
string += "0";
else
string += "1";
c = p;
p = hTree.node[p].parent;
}
char[] charArray = string.toCharArray();
for (int j = charArray.length-1; j>=0; j--){
str[i] +=charArray[j];
}
}
return str;
}
public String yiMaHuffMan(HufumanTree hTree,String string){
char[] bianma = string.toCharArray();
String yima = "";
int j = 1;
int temp = 0; //temp记录没有双亲结点的下标
for(int k=1;k<=hTree.node.length-1;k++){
if(hTree.node[k].parent == 0)
temp = k;
}
int s = temp ;
for (int i = 0; i < bianma.length; i++) {
if(hTree.node[s].Lchild==0&&hTree.node[s].Rchild==0) {
yima += hTree.node[s].data;
s = temp;
}
if(bianma[i] == '0'){
s = hTree.node[s].Lchild;
}
else if(bianma[i] == '1'){
s = hTree.node[s].Rchild;
}
}
yima += hTree.node[s].data;
return yima;
}
}
public class ZhuanHuaBianMa {
String string,s;
public void setString(String string){
this.string = string;
}
public void setS(String string){
this.s = string;
}
public String getString(){
HFbianma huffman = new HFbianma();
ZiFuTongJi tonFu = new ZiFuTongJi();
tonFu.setHuffmanString(string);
tonFu.zifu();
String st = "";
char[] ch = string.toCharArray();
HufumanTree tree = huffman.CrtHafushu(tonFu.getData(), tonFu.getWeight(), tonFu.getEnd());
for (int j = 0; j < ch.length; j++) {
for (int i = 1; i <= huffman.BianmaHuffman(tree, tonFu.getEnd()).length-1; i++) {
if(ch[j]==tonFu.getData()[i])
st +=huffman.BianmaHuffman(tree, tonFu.getEnd())[i];
}
}
return st;
}
public String getBianmaString(){
String st = "";
HFbianma huffman = new HFbianma();
ZiFuTongJi tonFu = new ZiFuTongJi();
tonFu.setHuffmanString(string);
tonFu.zifu();
HufumanTree tree = huffman.CrtHafushu(tonFu.getData(), tonFu.getWeight(), tonFu.getEnd());
for (int i = 1; i <= huffman.BianmaHuffman(tree, tonFu.getEnd()).length-1; i++) {
String str ="\t\t" + tonFu.getData()[i]+"----------->"+huffman.BianmaHuffman(tree,tonFu.getEnd())[i]+"\n";
st += str;
}
return st;
}
public String getYimaString(){
String st = "";
HFbianma huffman = new HFbianma();
ZiFuTongJi tonFu = new ZiFuTongJi();
tonFu.setHuffmanString(string);
tonFu.zifu();
char[] ch = string.toCharArray();
HufumanTree tree = huffman.CrtHafushu(tonFu.getData(), tonFu.getWeight(), tonFu.getEnd());
for (int i = 0; i < ch.length; i++) {
for (int j = 1; j <= tonFu.getEnd(); j++) {
if(ch[i]==tonFu.getData()[j])
st += huffman.BianmaHuffman(tree, tonFu.getEnd())[j];
}
}
return huffman.yiMaHuffMan(tree, st);
}
public String getSouceIsDecode(String s1,String s2){
char[] ch1 = s1.toCharArray();
char[] ch2 = s2.toCharArray();
int t = 0;
for (int i = 0; i < ch2.length; i++) {
if(ch1[i]!=ch2[i])
t = 1;
}
if(t == 0)
return "Ture";
else {
return "False";
}
}
}
class ZiFuTongJi{
String hufmanString = "";
char[] data = new char[1000];
int[] w = new int[1000];
int biaozhi=1;
public void setHuffmanString(String hufmanString){ //传入字符串
this.hufmanString=hufmanString;
}
public String getHuffmanString(){ //得到字符串
return hufmanString;
}
public boolean seach(char ch,char[] da,int n){ //查找
for (int i = 1; i <= n; i++) {
if(ch == da[i])
return true;
}
return false;
}
public void zifu(){
char[] str = hufmanString.toCharArray();
data[1] = str[0];
for (int i = 1; i < str.length; i++) { //统计字符出现的种类
if(!seach(str[i], data, biaozhi)){
biaozhi++;
data[biaozhi] = str[i];
}
}
for (int i1 = 0; i1 < str.length; i1++) { //统计字符出现的次数
for (int j = 1; j <= biaozhi; j++) {
if(str[i1] == data[j])
w[j]++;
}
}
}
public char[] getData(){
char[] data1 = new char[biaozhi+1];
for (int i2= 1; i2 <= biaozhi; i2++) {
data1[i2] = data[i2];
}
return data1;
}
public int[] getWeight(){
int[] weight = new int[biaozhi+1];
for (int i2= 1; i2 <= biaozhi; i2++) {
weight[i2] = w[i2];
}
return weight;
}
public int getEnd(){
return biaozhi;
}
}
布局设计:
主界面,<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<LinearLayout
android:id="@+id/ll_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="@+id/btn_one"
android:layout_width="80dp"
android:layout_height="80dp"
android:background="@drawable/desk1" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="@+id/btn_two"
android:layout_width="80dp"
android:layout_height="80dp"
android:background="@drawable/desk2" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="@+id/btn_three"
android:layout_width="80dp"
android:layout_height="80dp"
android:background="@drawable/desk3" />
</LinearLayout>
</LinearLayout>
<ImageView
android:id="@+id/imgv_overtab"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentTop="true"
android:background="@drawable/circle1" />
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/ll_tabs" />
</RelativeLayout>
欢迎布局,<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#ff00ff">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="110dp"
android:layout_gravity="center_horizontal"
android:text="XYRJ1404"
android:textSize="38sp"
android:textColor="#ffffff"
/>
<ImageView
android:id="@+id/wecomeImageView"
android:layout_height="120dp"
android:layout_width="120dp"
android:layout_marginTop="40dp"
android:layout_gravity="center_horizontal"
android:background="@drawable/xytb"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="15dp"
android:text="HAFUMAN"
android:textSize="28sp"
android:textColor="#ffffff"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:text="LWP"
android:textSize="38sp"
android:textColor="#ffffff"
/>
</LinearLayout>
三个子页面的布局,
子页面1:<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00E3E3" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="10dp"
android:orientation="vertical" >
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="60dp" >
<requestFocus />
</EditText>
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="更改souce文件" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/linearLayout1"
android:layout_marginTop="20dp"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="souce文件中各个哈夫曼编码如下:"
android:textSize="20sp" />
<Button
android:id="@+id/bianmaButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="souce文件中的字符编码"
/>
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="100dp" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/soucewenjianbianma"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</ScrollView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/linearLayout1"
android:layout_marginTop="180dp"
android:orientation="vertical" >
<Button
android:id="@+id/panduanButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="souce文件与decode文件是否相同:"
/>
<TextView
android:id="@+id/panduanTextView"
android:layout_width="match_parent"
android:layout_height="50dp"
android:textSize="30sp"
android:gravity="center"/>
</LinearLayout>
</RelativeLayout>
子页面2:<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#009100" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="162dp"
android:text="哈夫曼编码译码器"
android:gravity="center"
android:textSize="30sp" />
</RelativeLayout>
子页面3:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#750075" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="10dp"
android:orientation="vertical" >
<Button
android:id="@+id/souceButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="souce文件"
/>
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="70dp" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/souceTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</ScrollView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="140dp"
android:orientation="vertical" >
<Button
android:id="@+id/decodeButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="decode文件"
/>
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="70dp" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/decodeTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</ScrollView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="280dp"
android:orientation="vertical" >
<Button
android:id="@+id/codeButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="code文件"
/>
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="70dp" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/codeTextview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</ScrollView>
</LinearLayout>
</RelativeLayout>
AndroidMainfes文件如下:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.madeLi.hufuman"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.madeLi.hufuman.MainActivity"
android:label="@string/app_name" >
</activity>
<activity
android:name="com.madeLi.hufuman.WelcomActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>