2017-04-23 108 views
0

我正在使用volley來獲取網站的Html內容。我正在使用以下代碼。如何在TextView中添加換行符

RequestQueue queue = Volley.newRequestQueue(this); 
StringRequest stringRequest = new StringRequest(Request.Method.GET, sourl, 

      new Response.Listener<String>() { 
       @Override 
       public void onResponse(String response) { 
        String highlighted = highlighter.highlight("java", response.toString()); 
        mTextView.setText(Html.fromHtml(highlighted)); 
        //mTextView.setText(response.toString()); 
       } 
      }, new Response.ErrorListener() { 
     @Override 
     public void onErrorResponse(VolleyError error) { 
      mTextView.setText("That didn't work!"); 

     } 
    }); 
// Add the request to the RequestQueue. 
queue.add(stringRequest); 

但我希望不是在一個時間來加載通過在線網站線的HTML內容,我想在結束每行設置成EditText前加斷線之後,我不想換字。 電流輸出如下圖所示。

enter image description here

回答

0

有2種方式來做到這一點

1)將寬度設置爲0dp在你的XML文件中的TextViewandroid:width="0dp"

2)家長設置爲一個適當的寬度(在這種情況下爲FILL_PARENTWRAP_CONTENT並且使用android:layout_weight=1代表需要被包裝的TextView

如果不工作,然後嘗試將這些屬性添加到TextView

android:singleLine="false"

android:scrollHorizontally="false"

android:ellipsize="none"

你也可以做到這一點編程爲下

// Get handle to TextView 
TextView tv = findViewByID(R.id.text_view) ; 

tv.setHorizontallyScrolling(false); 
tv.setSingleLine(false); 
+0

其實我不換行 –

+0

發佈你的XML文件 – LumberHack

+0

其實我已經通過添加textView.scrollHorizo​​ntally(false)來完成了; –