2010-10-06 86 views
1

TextView滾動問題

我編寫的應用程序顯示正在運行的進程列表,我使用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你們幫助我爲什麼滾動沒有發生在我的手機中的第二種方法,因爲它在我的模擬器中正常工作?

回答

1

爲什麼不把你的textview放在你的xml佈局的滾動視圖中。嘗試,我認爲它的工作

+0

謝謝..我檢查 – Shijilal 2010-10-06 06:07:14

0

我已經修改了與滾動型main.xml中通過ud_an

<?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"/> 

<ScrollView android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 

<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" 
    /> 
</ScrollView> 
</RelativeLayout> 

現在滾動的第二種方法是工作太..謝謝ud_an

但爲什麼的建議模擬器和我的手機在以前的情況下冷漠地在模擬器中滾動和移動沒有滾動?