2012-12-16 54 views
3

現在textview顯示語句,如果我將滾動遠離底部。看起來promis textview變得很大。有沒有辦法解決它?textview不顯示文本(一個文本視圖推遠另一個遠離屏幕)

screenshot 星空下的一切都是promis textview的一部分。這是一個字符串與產生的承諾

prm = doc.getElementsByTagName("promise"); 
      for (int j = 0; j < prm.getLength(); j++) { 
       prom += parser.getValue(e, KEY_PROMISES, j) + "\n"; 

      } 
      prom.substring(0,prom.lastIndexOf('\n')); 

佈局

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/widget32" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <RelativeLayout 
     android:id="@+id/top" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 

     <ImageView 
      android:id="@+id/face" 
      android:layout_width="68dp" 
      android:layout_height="68dp" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentTop="true" /> 

     <TextView 
      android:id="@+id/name" 
      android:layout_width="243dp" 
      android:layout_height="35dp" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentTop="true" 
      android:layout_toRightOf="@id/face" 
      android:text="from" /> 

     <TextView 
      android:id="@+id/office" 
      android:layout_width="242dp" 
      android:layout_height="wrap_content" 
      android:layout_alignBottom="@+id/face" 
      android:layout_alignParentRight="true" 
      android:layout_below="@+id/name" 
      android:layout_toRightOf="@id/face" 
      android:text="subject" /> 
    </RelativeLayout> 

    <RatingBar 
     android:id="@+id/ratingBar1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_below="@+id/top" 
     android:numStars="6" 
     android:singleLine="false" /> 

    <TextView 
     android:id="@+id/promises" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_below="@+id/ratingBar1" 
     android:layout_marginTop="5dp" 
     android:text="TextView" /> 

    <ScrollView 
     android:id="@+id/scroll" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" 
     android:layout_below="@+id/promises" 
     android:layout_marginRight="22dp" 
     android:layout_marginTop="26dp" > 

     <TextView 
      android:id="@+id/statement" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="TextView" /> 
    </ScrollView> 

</RelativeLayout> 

活動我的應用程序的幾個換行符 screenshot2另一屏幕

代碼

public class SingleMenuItemActivity extends Activity { 


    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.candidate); 
     Log.d("here ?", "No "); 
     int loader = R.drawable.loader; 
     // getting intent data 
     Intent in = getIntent(); 
     Log.d("here ?", "No "); 
     // Get XML values from previous intent 
     String name = in.getStringExtra("name"); 
     Log.d("Name ", name); 
     Log.d("here ?", "No "); 
     DatabaseHandler db = new DatabaseHandler(this); 
     Log.d("here ?", "No "); 
     Candidate p = db.getCandidate(name); 
     Log.d("Did i take candidate? ", "yea "); 
     db.close(); 
     Log.d("Statement", p.get_statment()); 
     // Displaying all values on the screen 
     TextView lblName = (TextView) findViewById(R.id.name); 
     TextView lblOffice = (TextView) findViewById(R.id.office); 
     TextView lblPromise = (TextView) findViewById(R.id.promises); 
     TextView lblStatement = (TextView) findViewById(R.id.statement); 
     ImageView lblFace = (ImageView) findViewById(R.id.face); 
     RatingBar lblRating = (RatingBar) findViewById(R.id.ratingBar1); 
     ImageLoader imgLoader = new ImageLoader(this); 
     lblName.setText(p.get_name()); 
     lblOffice.setText(p.get_office()); 
     lblPromise.setText(p.get_promises()); 
     lblStatement.setText(p.get_statment()); 
     lblRating.setRating(p.get_ranking()); 
     imgLoader.DisplayImage(p.get_photograph(), loader, lblFace); 

    } 
} 

logcat的說:p .get_statment()有親每值在它

12-16 05:07:16.089: D/Statement(279): I strive for the highest standards of appearance and personal grooming. If, like me, you think that the University's reputation is being dragged down by lecturers who have little or no regard for fashion and are content to wear ill-fitting or patched clothes then vote for me: the stylish choice. 

信譽低後圖像%)

+0

並且它示出了一些其它的文本,或者它是BL ank還是失蹤? – iagreen

+0

textview語句空白,所有其他都顯示爲 – Yarh

回答

0

好吧,我找到解決辦法,而且我不明白爲什麼TextView的擴大這麼多,我知道現在該怎麼解決它:) 首先我們需要知道行數,這串會產生

private static int countLines(String str){ 
      String[] lines = str.split("\r\n|\r|\n"); 
      return lines.length; 
     } 

然後簡單地限制的TextView在尺寸

lblPromise.setMaxLines(countLines(p.get_promises())); 
2

您的代碼似乎是正確的。 如果textView的編號爲lblStatement沒有顯示文字,那麼您可能有一個背景,您無法辨別文字(所以嘗試更改顏色),或者邊距不適合textview位置。

如果p.get_statment()具有正確的值,則沒有其他可能的原因。

3

它看起來像你的RatingBar被覆蓋你statement的TextView:

<RatingBar 
    android:layout_above="@+id/statement" 
    ... /> 

也許你的意思是layout_below

而且你promises的TextView有非常大的上邊距,它可以推動statement的TextView關閉屏幕的底部:

<TextView 
    android:id="@+id/promises" 
    android:layout_marginTop="124dp" 
    ... /> 

加成
顯然也有一些在TextView的末尾添加換行符。如果不能從源頭上消除這些字符,你可以使用trim()

prom = prom.trim(); 
+0

我改變了保證金爲5和固定對齊,但仍然沒有結果 – Yarh

+0

嗯,你可以張貼截圖嗎? (您是否嘗試過使用ScrollView,可以肯定?) – Sam

+0

我試圖將語句放在滾動視圖中,但是我沒有解決這個問題,所以我只是撤消它。 http://vk.com/photo17601636_293394853還有屏幕截圖 evrything下的評級欄是承諾textview – Yarh

相關問題