最佳实践显示大文本数据在Android有何看法? [英] Best practice to show big text data in an android view?
问题描述
在我的应用程序的我的信息方面我想告诉我的应用程序的简要说明。为此,我需要创建大量文本的视图。是什么,最好的做法是什么?其实我创建了一个线性布局与滚动视图,在此我将添加我的文字,也应包含一些变量值如我的应用程序版本。但我不知道是否有更好的方法来做到这一点?
In my information area of my app I want to show a brief description of my app. For that I need to create a view with a lot of text. What is the best practice for that ? Actually I created a Linear Layout with a Scrollview, in this i will add my text, which also should contain some variable values e.g. my app version. But I do not know if there are better ways to do that?
下面是我目前的做法:
<LinearLayout
android:id="@+id/information_content"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@id/bottom_footer"
android:layout_below="@id/top_header"
android:layout_marginLeft="@dimen/marginLeft"
android:layout_alignParentRight="true"
android:layout_weight="1"
android:orientation="vertical" >
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<EditText
android:id="@+id/info_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textMultiLine"
android:text="Hallo das ist ein test!!!
dsf" />
</LinearLayout>
</ScrollView>
</LinearLayout>
任何建议?
Any recommendations?
感谢
推荐答案
您可能正在寻找一个典型的关于屏幕与可以使用HTML格式的简单滚动文本。
You are probably looking for a typical "About Screen" with simple scrollable text that may be formatted using HTML.
首先,这里是布局 /layout/about_layout.xml
。你不需要包装在一个额外的LinearLayout你的看法。
Firstly, here is the layout /layout/about_layout.xml
. You don't need to wrap your view in an extra LinearLayout.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="12dp" >
<TextView
android:id="@+id/about_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
</ScrollView>
之后,以下内容添加到您的 /values/strings.xml
:
<string name="about_text">
<![CDATA[
Author: Your name<br/><br/>Your description text, changelog, licences etc... ]]>
</string>
最后,使用的布局在<$ C $ C> AboutActivity.java ,显示该字符串HTML格式,并与一些自动更新的信息,丰富它,如版本号。
Finally, use the layout in your AboutActivity.java
, display the string HTML-formatted and enrich it with some auto-updated information, such as your version number.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.about_layout);
String versionName = "";
try {
PackageInfo pinfo = getPackageManager().getPackageInfo(getPackageName(), 0);
versionName = pinfo.versionName;
} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
TextView aboutTextView = (TextView) findViewById(R.id.about_text_view);
aboutText = Html.fromHtml("<h1>Your App Name, Version " + versionName + "</h1>"
+ getString(R.string.about_text));
aboutTextView.setText(aboutText);
}
这就是我如何处理关于画面在我的应用程序。对不起,这个答案可能会有点洁癖,但我认为这是一个普遍要求的图案。
That's how I deal with the About Screen in my app. Sorry for this answer might be a bit over the top, but I think it's a commonly requested pattern.
这篇关于最佳实践显示大文本数据在Android有何看法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!