【发布时间】:2013-08-12 19:49:58
【问题描述】:
这里还是个菜鸟……
我正在尝试渲染足球比赛的规格(球队、时间、锦标赛等)
我已经创建了一个 team.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/teamImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="2dp"
android:adjustViewBounds="true"
android:src="@drawable/sofabold_launcher"
android:layout_alignWithParentIfMissing="false"
android:clickable="false"
android:cropToPadding="true"
android:contentDescription="@string/teamLogoContentDescription"/>
<TextView
android:id="@id/teamName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/teamName"
android:textSize="14sp"
android:textStyle="bold"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/teamImageView"/>
</RelativeLayout>
一个teams.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="bottom"
android:orientation="vertical" >
<include
android:layout_width="wrap_content"
android:layout_height="wrap_content"
layout="@layout/team"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:id="@+id/homeTeam"/>
<include
android:layout_width="wrap_content"
android:layout_height="wrap_content"
layout="@layout/team"
android:layout_below="@id/homeTeam"
android:id="@+id/awayTeam"/>
</RelativeLayout>
然后我有一个 matchLayout.xml,包括我的 teams.xml
我最初的尝试是创建一个具有不同元素的大布局,并在我的 matchHolder 中通过它们的 id 引用它们,并使用类似
的东西填充它们matchHolder.homeTeamName.setText(match.getHomeTeamName());
现在我尝试将我的 populateMatchHolder 更改为:
private void populateMatchHolder(View convertView, BaseMatchHolder matchHolder) {
matchHolder.teams = (RelativeLayout) convertView.findViewById(R.id.teams);
}
现在我不知道如何在另一个RelativeLayout(匹配)中引用RelativeLayout(团队)中的TextView(主队名称)。
我是否完全错过了这里的重点?我需要在某处有一个名为 homeTeamName 的 id 吗?和 awayTeamName?拥有两次 teamName 还不够吗?一次包含在 team.xml 的 homeTeam 中,一次包含在 team.xml 的 awayTeam 中。
希望我的意思有点清楚 :-) 已经很晚了,我累了 :-/
提前致谢
【问题讨论】: