我有三个字符串数据数组,我想通过适配器将它们膨胀到列表中。问题是行的高度是固定的,即使我放了 30dip、50dip、100dip,我也会增加,高度没有生效:(
这是我的 XML 代码行:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android = "http://schemas.android.com/apk/res/android"
android:layout_width = "fill_parent"
android:layout_height = "fill_parent" // even when i change it to 30dip, 50dip and etc. doesn't take effect
android:background = "@color/septator_grey_light">
<TextView
android:id = "@+id/tvStatisticsTitle"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_centerInParent = "true"
android:gravity = "center_vertical|center"
android:text = "@string/test_10"
style = "@style/simpletopic.black" />
<TextView
android:id = "@+id/tvStatisticsHost"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_alignBaseline = "@+id/tvStatisticsTitle"
android:layout_alignBottom = "@+id/tvStatisticsTitle"
android:layout_alignParentLeft = "true"
android:layout_marginLeft = "20dp"
android:text = "@string/test_02"
style = "@style/simpletopic.black.big" />
<TextView
android:id = "@+id/tvStatisticsGeust"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_alignBaseline = "@+id/tvStatisticsTitle"
android:layout_alignBottom = "@+id/tvStatisticsTitle"
android:layout_alignParentRight = "true"
android:layout_marginRight = "20dp"
android:text = "@string/test_02"
style = "@style/simpletopic.black.big" />
</RelativeLayout>
我的适配器代码如下。
public class StatisticsAdapter extends BaseAdapter {
private final String TAG = "*** StatisticsAdapter ***";
private final String[] TITLE = {"Shots on Target", "Shots Wide", "Offsides", "Corners", "Possession", "Fouls"};
private LayoutInflater myInflater;
private String[] hostInfo;
private String[] guestInfo;
public StatisticsAdapter(Context context) {
myInflater = LayoutInflater.from(context);
Log.i(TAG, "Adapter setuped successfully.");
}
public void setData(Statistics statisticsItems) {
hostInfo = new String[6];
guestInfo = new String[6];
hostInfo[0] = statisticsItems.getHomeTeamShotsTarget();
hostInfo[1] = statisticsItems.getHomeTeamShotsWide();
hostInfo[2] = statisticsItems.getHomeTeamOffsides();
hostInfo[3] = statisticsItems.getHomeTeamCorners();
hostInfo[4] = statisticsItems.getHomeTeamPossession();
hostInfo[5] = statisticsItems.getHomeTeamFouls();
guestInfo[0] = statisticsItems.getAwayTeamShotsTarget();
guestInfo[1] = statisticsItems.getAwayTeamShotsWide();
guestInfo[2] = statisticsItems.getAwayTeamOffsides();
guestInfo[3] = statisticsItems.getAwayTeamCorners();
guestInfo[4] = statisticsItems.getAwayTeamPossession();
guestInfo[5] = statisticsItems.getAwayTeamFouls();
Log.i(TAG, "Data passed to the adapter.");
}
@Override
public int getCount() {
return TITLE.length;
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = myInflater.inflate(R.layout.list_statistics_adapter, null);
holder = new ViewHolder();
holder.tvStatisticsHost = (TextView) convertView.findViewById(R.id.tvStatisticsHost);
holder.tvStatisticsTitle = (TextView) convertView.findViewById(R.id.tvStatisticsTitle);
holder.tvStatisticsGeust = (TextView) convertView.findViewById(R.id.tvStatisticsGeust);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.tvStatisticsHost.setText(hostInfo[position]);
holder.tvStatisticsTitle.setText(TITLE[position]);
holder.tvStatisticsGeust.setText(guestInfo[position]);
return convertView;
}
static class ViewHolder {
TextView tvStatisticsHost;
TextView tvStatisticsTitle;
TextView tvStatisticsGeust;
}
}
任何建议将不胜感激。谢谢