2017-04-23 123 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)来完成了; –