【问题标题】:Views in list are not at the corrects size列表中的视图大小不正确
【发布时间】:2013-04-16 19:59:38
【问题描述】:

我有一个列表视图和一个适配器。我的问题是列表中的行始终为"wrap content",即使我特别将高度指定为"150dp"

这是我的适配器:

private class LiveEventsAdapter extends BaseAdapter {

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View contentView = convertView;
        if (contentView == null) {
            LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            contentView = inflater.inflate(R.layout.live_match_row, null);
            TypefaceManager.getInstance(LiveMatchActivity.this).assignTypeface(contentView);
        }

        if (events != null) {
            Event event = events.getEventsList().get(position);

            TypefaceManager typefaceManager = TypefaceManager.getInstance(LiveMatchActivity.this);
            TextView eventText;
            TextView minute;
            ImageView eventIcon;

            minute = (TextView) contentView.findViewById(R.id.live_match_minute);
            if (event.getOrientation().equals("home")) {
                eventText = (TextView) contentView.findViewById(R.id.home_team_event_text);
                eventIcon = (ImageView) contentView.findViewById(R.id.home_team_event_img);
            } else {
                eventText = (TextView) contentView.findViewById(R.id.away_team_event_text);
                eventIcon = (ImageView) contentView.findViewById(R.id.away_team_event_img);
            }
            minute.setText(event.getMinute() + "\'");
            eventText.setText(event.getDescription());
            minute.setTypeface(typefaceManager.getTypeface("bold"));
            eventText.setTypeface(typefaceManager.getTypeface("bold"));
        }   
}

我就是这样"setadapter":

ListView eventsListView = (ListView) findViewById(R.id.live_match_list);
        eventsListView.setAdapter(new LiveEventsAdapter());

那是我的rows layout:

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="@drawable/background_button" >

<TextView
    android:id="@+id/live_match_minute"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:text="82&apos;" />

<TextView
    android:id="@+id/home_team_event_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="false"
    android:layout_alignRight="@+id/home_team_event_img"
    android:layout_centerVertical="true"
    android:paddingLeft="4dp"
    android:paddingRight="4dp" />

<ImageView
    android:id="@+id/home_team_event_img"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentTop="true"
    android:layout_centerVertical="true"
    android:layout_marginRight="4dp"
    android:layout_toLeftOf="@+id/live_match_minute" />

<ImageView
    android:id="@+id/away_team_event_img"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="false"
    android:layout_centerVertical="true"
    android:layout_marginLeft="4dp"
    android:layout_toRightOf="@+id/live_match_minute" />

<TextView
    android:id="@+id/away_team_event_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="false"
    android:layout_centerVertical="true"
    android:layout_toRightOf="@+id/away_team_event_img"
    android:paddingLeft="4dp"
    android:paddingRight="4dp" />

为什么我的列表中的行总是设置为相同的大小,无论我放入什么?

【问题讨论】:

    标签: android listview layout size height


    【解决方案1】:

    这行不通。

    这是你应该做的。

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >
    
        <RelativeLayout 
        android:layout_width="match_parent"
        android:layout_height="150dp"
        android:background="@drawable/background_button" >
    
            <TextView
                android:id="@+id/live_match_minute"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_centerVertical="true"
                android:text="82&apos;" />
    
        </RelativeLayout>
    </RelativeLayout>
    

    基本上,添加另一个布局并指定该布局的高度。 使用适配器视图时,为根布局指定高度不起作用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多