我編寫的應用程序顯示正在運行的進程列表,我使用TextView在屏幕上顯示正在運行的進程。 我正在嘗試2種不同的顯示TextView的方法。 在一種方法我是declearing在代碼本身
TextView tv = new TextView(this);
this.setContentView(tv);
在第二種方法中我是declearing佈局在main.xml中文件
setContentView(R.layout.main);
TextView tv=(TextView) findViewById(R.id.RunApp);
對於兩種我使用的方法的TextView的setMovementMethod具有用於我的TextView
tv.setMovementMethod(new ScrollingMovementMethod());
該程序在emulator.But運行良好,如果我使用第二種方法則SCR滾動運動如果我在移動設備上運行應用程序,則不會發生問題。在模擬器中工作正常。爲什麼在我的Android 2.1三星Galaxy S中表現不同? 爲什麼滾動不在第二個方法中發生??。第一種方法正在進行滾動,在我的手機中沒有任何問題。
這是我的代碼..
public class listRunningApps extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
//TextView tv=(TextView) findViewById(R.id.RunApp);
TextView tv = new TextView(this);
this.setContentView(tv);
tv.setMovementMethod(new ScrollingMovementMethod());
ActivityManager actvityManager = (ActivityManager)
this.getSystemService(ACTIVITY_SERVICE);
List<RunningAppProcessInfo> procInfos = actvityManager.getRunningAppProcesses();
for(int j=0; j < 2; j++)
/*I have done iteration 2 times so that we have a long process list
sufficeint enough for scrolling*/
{
for(int i = 0; i < procInfos.size(); i++)
{
tv.setText(tv.getText().toString()+procInfos.get(i).processName+
" " + String.valueOf(procInfos.get(i).processName.length())+"\n");
}
tv.setText(tv.getText().toString()+"----------------------------"+"\n");
}
}
}
這是我的main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/jsttxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Testing TextView Scrolling"/>
<TextView
android:id="@+id/RunApp"
android:layout_marginLeft="30px"
android:layout_marginRight="30px"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/jsttxt"
/>
</RelativeLayout>
在第一種方法滾動在我的手機來了,沒有任何issue..Can你們幫助我爲什麼滾動沒有發生在我的手機中的第二種方法,因爲它在我的模擬器中正常工作?
謝謝..我檢查 – Shijilal 2010-10-06 06:07:14