package training.android.com; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.view.KeyEvent; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.ScrollView; import android.widget.TextView; import android.widget.Toast; public class fileWriteRead extends Activity implements OnClickListener { /** Called when the activity is first created. */ private EditText edit_Text;// 编缉文本框 private Button btn_Save;// 保相聚按钮 private String text_of_input;// 输入文本值 private OutputStream os;// 输出流 private TextView showMyText;// 显示文本 private Button btnOpenText, btnCleanText;// 打开与清空按钮事件 private Button btnOpenRaw; private String Text_of_output;// 输入出文本 private InputStream is;// 输入流 private InputStream iputRaw;//静态文件流 private byte[] b; private ScrollView scroll; private int ori=0; /** * 页面的初始化 * */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // setContentView(R.layout.main); showLayout("main"); UIinit("main"); Logic("main"); } /** * 通过页面名称去显示各页面信息 创建人:周昕 创建时间:2010-4-8 方法名称:showLayout * * @param layoutName */ private void showLayout(String layoutName) { if (layoutName.equals("main")) { setContentView(R.layout.main); } if (layoutName.equals("openfile")) { setContentView(R.layout.openfile); } } /** * 通过页面名称去初始化控件 * * @param uiName * 创建人:周昕 &&&&&&&& 创建时间:2010-4-8 */ private void UIinit(String uiName) { if (uiName.equals("main")) { edit_Text = (EditText) findViewById(R.id.Edit_text); btn_Save = (Button) findViewById(R.id.Button_save); } if (uiName.equals("openfile")) { btnOpenText = (Button) findViewById(R.id.Button_openTxt); btnCleanText = (Button) findViewById(R.id.Button_clean); btnOpenRaw = (Button) findViewById(R.id.Button_openRaw); showMyText = (TextView) findViewById(R.id.TextView_showTxt); } } /** * 通过页面名称去对各Button指定事件 * * @param pageName * 创建人:周昕******** 创建时间:2010-4-8 */ private void Logic(String pageName) { if (pageName.equals("main")) { btn_Save.setOnClickListener(this); } if (pageName.equals("openfile")) { btnOpenText.setOnClickListener(this); btnCleanText.setOnClickListener(this); btnOpenRaw.setOnClickListener(this); } } /** * 在Toast中显示指定的字段 * * @param strTitle */ private void NoteDebug(String strTitle) { Toast.makeText(this, strTitle, Toast.LENGTH_SHORT).show(); } @Override public void onClick(View v) { // TODO Auto-generated method stub switch (v.getId()) { case R.id.Button_save: NoteDebug("文件保存"); text_of_input = edit_Text.getText().toString(); try { os = this.openFileOutput("txtME", MODE_PRIVATE); os.write(text_of_input.getBytes()); } catch (FileNotFoundException e) { NoteDebug("文件关闭失败" + e); } catch (IOException e) { NoteDebug("文件写入失败" + e); } finally { try { os.close(); } catch (IOException e) { NoteDebug("关闭文件失败" + e); } } edit_Text.setText(""); break; case R.id.Button_openTxt: NoteDebug("打开文件"); try { is = this.openFileInput("txtME"); b = new byte[1024]; int length = is.read(b); Text_of_output = new String(b); setTitle("文件字数" + length); showMyText.setText(Text_of_output); } catch (FileNotFoundException e) { NoteDebug("文件打开失败" + e); } catch (IOException e) { // TODO Auto-generated catch block NoteDebug("文件读取失败" + e); } finally { try { is.close(); } catch (IOException e) { NoteDebug("文件关闭失败" + e); } } break; case R.id.Button_openRaw: NoteDebug("打开静态文件"); try { iputRaw = this.getResources().openRawResource(R.raw.filetext); b = new byte[102400]; int length = iputRaw.read(b); Text_of_output=""; Text_of_output = new String(b); setTitle("静态文件字数" + length); showMyText.setText(Text_of_output); showMyText.setHorizontallyScrolling(true); scroll = (ScrollView)findViewById(R.id.scroll); scroll.smoothScrollBy(ori, 0); } catch (FileNotFoundException e) { NoteDebug("静态文件打开失败" + e); } catch (IOException e) { // TODO Auto-generated catch block NoteDebug("静态文件读取失败" + e); } finally { try { iputRaw.close(); } catch (IOException e) { NoteDebug("静态文件关闭失败" + e); } } break; case R.id.Button_clean: NoteDebug("清空文件"); showMyText.setText(""); NoteDebug("清空"); break; } } public boolean onCreateOptionsMenu(Menu menu) { menu.add(0, 1, 1, "edit"); menu.add(0, 2, 2, "open"); menu.add(0, 3, 3, "clear"); return super.onCreateOptionsMenu(menu); } public boolean onOptionsItemSelected(MenuItem items) { switch (items.getItemId()) { case 1: showLayout("main"); UIinit("main"); Logic("main"); NoteDebug("编缉文件"); break; case 2: showLayout("openfile"); UIinit("openfile"); Logic("openfile"); NoteDebug("打开件"); break; case 3: showLayout("openfile"); UIinit("openfile"); Logic("openfile"); NoteDebug("清空文件"); break; } return super.onOptionsItemSelected(items); } private Handler message = new Handler(){ public void handleMessage(Message msg) { doScrow(); } }; public class TimerLoop implements Runnable { @Override public void run() { // TODO Auto-generated method stub while(true){ loop(500); message.sendEmptyMessage(0); } } } //因为sleep()似乎不好用 所以采用这种方法计时 public void loop(long i){ long j = i; while(j>0){ j = j-1; } } public boolean onKeyDown(int keyCode, KeyEvent msg){ // Thread loop = new Thread(new TimerLoop()); // loop.start(); return super.onKeyDown(keyCode, msg); } public void doScrow(){ int now = scroll.getScrollY(); if(ori == now){ scroll.scrollTo(now, 0); ori = -1; } else { scroll.smoothScrollBy(10, 10); ori = now; } } }
main.xml文件
<?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" > <EditText android:id="@+id/Edit_text" android:layout_width="fill_parent" android:layout_height="350px"> </EditText> <Button android:text="保存" android:id="@+id/Button_save" android:layout_width="80px" android:layout_height="wrap_content"> </Button> </LinearLayout>
open.xml
<?xml version="1.0" encoding="UTF-8"?> <AbsoluteLayout android:id="@+id/openlayout" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"> <!-- <ScrollView android:layout_weight="1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:scrollbars="vertical" android:fadingEdge="vertical" android:id="@+id/scroll"> --> <ScrollView android:id="@+id/scroll" android:layout_width="fill_parent" android:layout_height="300dip" > <LinearLayout android:layout_width="fill_parent" android:layout_height="380px"> <TextView android:id="@+id/TextView_showTxt" android:layout_width="314px" android:layout_height="373px" android:scrollbars="vertical" android:fadingEdge="vertical" android:autoText="true" android:layout_x="3px" android:layout_y="3px" > <!-- android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forever" --> </TextView> </LinearLayout> </ScrollView> <Button android:id="@+id/Button_openTxt" android:layout_width="80px" android:layout_height="wrap_content" android:text="打开" android:layout_x="2px" android:layout_y="378px"> </Button> <Button android:id="@+id/Button_openRaw" android:layout_width="80px" android:layout_height="wrap_content" android:text="静态文件" android:layout_x="102px" android:layout_y="378px"> </Button> <Button android:id="@+id/Button_clean" android:layout_width="80px" android:layout_height="wrap_content" android:text="清空" android:layout_x="239px" android:layout_y="378px"> </Button> </AbsoluteLayout>
AndroidMainfest.xml
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="training.android.com" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".fileWriteRead" 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> <uses-sdk android:minSdkVersion="3" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission> <uses-permission android:name="android.permission.MODE_WORLD_READABLE"></uses-permission> <uses-permission android:name="android.permission.MODE_WORLD_WRITEABLE"></uses-permission> </manifest>
您还没有登录,请您登录后再发表评论
本文实例讲述了Android TextView实现垂直滚动效果的方法。分享给大家供大家参考,具体如下: 在TextView中,如果文本很长,可能需要实现垂直滚动显示文本的效果。这里需要在XML布局文件中为TextView设置如下几个属性...
这是一个关于TextView上下滚动的效果,详情请前往博客浏览http://blog.csdn.net/u014452224/article/details/53101507
多条新闻的title横向滚动播放,并可点击。
自定义TextView,可实现多行textView的滚动,自定义颜色、大小、滚动速度和行间距
Android实现TextView文字滚动
Android TextView自动滚动,可以上下自动滚动也可以左右自动滚动,使用方便
android垂直滚动的textview
android之点击自动滚动textview
Android:TextView的垂直滚动效果和上下滚动效果,原生动画实现
项目中欢迎词多的时候需要实现上下滚动,了解到在android中TextView可以轻松实现横向跑马灯效果,但是对垂直滚动没有直接的支持方法,于是百度上谷歌,谷歌上百度,最终还是没有发现一个拿来即用的demo,呵呵,于是...
Android三种方法实现TextView文字滚动效果,很多人叫做跑马灯,这个不是图片滚动,是纯文字版的,我这android环境Down掉了,死活调试不起来,没截图了,需要的自行下载本源码包,代码中有中文注释,从代码看,除了...
android 逐行逐字显示的textview 播放通知的字幕 逐字逐行显示。可以控制显示的次数。
listview textview 水平滚动,用了Adapter,一次滚动两个textview
android TextView android TextView
android源代码--TextView 向上滚动效果 自定义一个Layout继承LinearLayout,内含TextView, 用TranslateAnimation实现向上滚动的效果。 如果只有一行字,就不滚动, 2行以上才有必要滚动。
Android自动滚动的TextView,源码里面有两个自定义的TextView,一个上下自动滚动,一个左右自动滚动,用起来都非常简单;
两个经典例子,包括android TextView水平滚动和垂直滚动效果
主要介绍了Android实现在TextView文字过长时省略部分或滚动显示的方法,结合实例形式分析了Android中TextView控件文字显示及滚动效果相关操作技巧,需要的朋友可以参考下
android TextView 支持CSS样式
相关推荐
本文实例讲述了Android TextView实现垂直滚动效果的方法。分享给大家供大家参考,具体如下: 在TextView中,如果文本很长,可能需要实现垂直滚动显示文本的效果。这里需要在XML布局文件中为TextView设置如下几个属性...
这是一个关于TextView上下滚动的效果,详情请前往博客浏览http://blog.csdn.net/u014452224/article/details/53101507
多条新闻的title横向滚动播放,并可点击。
自定义TextView,可实现多行textView的滚动,自定义颜色、大小、滚动速度和行间距
Android实现TextView文字滚动
Android TextView自动滚动,可以上下自动滚动也可以左右自动滚动,使用方便
android垂直滚动的textview
android之点击自动滚动textview
Android:TextView的垂直滚动效果和上下滚动效果,原生动画实现
项目中欢迎词多的时候需要实现上下滚动,了解到在android中TextView可以轻松实现横向跑马灯效果,但是对垂直滚动没有直接的支持方法,于是百度上谷歌,谷歌上百度,最终还是没有发现一个拿来即用的demo,呵呵,于是...
Android三种方法实现TextView文字滚动效果,很多人叫做跑马灯,这个不是图片滚动,是纯文字版的,我这android环境Down掉了,死活调试不起来,没截图了,需要的自行下载本源码包,代码中有中文注释,从代码看,除了...
android 逐行逐字显示的textview 播放通知的字幕 逐字逐行显示。可以控制显示的次数。
listview textview 水平滚动,用了Adapter,一次滚动两个textview
android TextView android TextView
android源代码--TextView 向上滚动效果 自定义一个Layout继承LinearLayout,内含TextView, 用TranslateAnimation实现向上滚动的效果。 如果只有一行字,就不滚动, 2行以上才有必要滚动。
Android自动滚动的TextView,源码里面有两个自定义的TextView,一个上下自动滚动,一个左右自动滚动,用起来都非常简单;
两个经典例子,包括android TextView水平滚动和垂直滚动效果
主要介绍了Android实现在TextView文字过长时省略部分或滚动显示的方法,结合实例形式分析了Android中TextView控件文字显示及滚动效果相关操作技巧,需要的朋友可以参考下
android TextView 支持CSS样式