問題描述
我只是想以某種方式在我的線性布局中添加一個新行:
I just want to add a new line somehow to my linear layout:
layout = (LinearLayout) findViewById (R.id.layout);
... //some other code where I've appended some strings already
final TextView nline = new TextView(this);
nline.setText(Html.fromHtml("<br>")); //i also tried: nline.setText("
");
layout.addView(nline);
但這只是增加了幾個空格.有人可以幫我嗎?謝謝.
But this just adds a few spaces. Can someone help me out? Thanks.
推薦答案
如果您只想在其他兩個視圖之間留出一些空白空間,您可以在 XML 中執行此操作(假設您使用 XML 進行布局).像這樣的東西可以工作,基本上是放置一個具有透明背景和給定高度的視圖.這是假設您在 TextView 中具有所需的任何參數.
If you just want to have some empty space between two other views, you could do this in your XML (assuming you're using XML for the layout). Something like this could work, basically putting in a View with a transparent background and given height. This is assuming you have whatever parameters you want in your TextViews.
<TextView />
<View android:background="#00000000"
android:layout_height="12dp" //or whatever density pixel height you want
android:layout_width="fill_parent" />
<TextView />
此外,在您上面嘗試的內容中...您可以嘗試使用空格和換行符...這可能會起作用.
Also, in what you tried above... you could try a space and newline... that might work.
nline.setText("
");
這篇關于Java android:使用 TextView 添加換行符的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!