我的应用程序首先有一个文本视图来显示文本。然后我想使文本对齐,但在Android中,无法在文本视图中实现文本对齐。为了使文本对齐,我正在从此链接获取帮助。我正在遵循@Kondzio提供的答案,但它不起作用。我不知道我的代码哪里出了问题。
代码-
public class Benefits extends Activity{
private Button back;
LinearLayout bText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.benefits);
WebView view = new WebView(this);
view.setVerticalScrollBarEnabled(true);
((LinearLayout)findViewById(R.id.bText)).addView(view);
view.loadData(getString(R.string.benef), "text/html", "utf-8");
back.setOnClickListener(new View.OnClickListener(){
public void onClick(View v)
{
finish();
}
});
}
}
Xml-
<LinearLayout
android:id="@+id/bText"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="4"
android:gravity="center">
</LinearLayout>
在strings.xml文件中 -
<string name="benef">
<![CDATA[
<html>
<head></head>
<body style="text-align:justify;color:gray;background-color:black;">
"1.some text\n
2.some text\n
.............
</body>
</html>
]]>
</string>
我将scrollbarenabled设置为true来使我的文本可以进行垂直滚动。