【发布时间】:2012-05-14 00:15:37
【问题描述】:
我正在创建一个应用程序,它在每个活动的顶部都有标题,到目前为止我一直在这样做:
为每个页面创建一个 header.xml。但我认为必须有更有效的方法。
我可以有一个常量 header.xml,然后在我的 onCreate 方法中更改文本的值。
这是我迄今为止一直在做的事情:
选择活动,
带有布局的chooseact.xml
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/white">
<include layout="@layout/selectheader" />
<include layout="@layout/redcell" />
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</TableLayout>
里面有一个header.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="60dp"
android:src="@drawable/headerrect" />
<TextView
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:gravity="center"
android:text="@string/leagues"
android:textColor="@color/white"
android:textSize="25dp"
android:textStyle="bold"/>
</RelativeLayout>
【问题讨论】:
-
那么你的问题是什么?
-
他想要一种更有效的方法来更改文本视图而不创建新字符串,对吧?
-
基于这里,你做得很好,只是仔细检查developer.android.com/resources/articles/…