2013-04-23 1 views
0

목록보기와 어댑터가 있습니다. 내 문제는 내가 특별히 "150dp"로 높이를 명시하더라도 목록의 행은 항상 "wrap content"입니다. 목록보기가 올바른 크기가 아닙니다.

내 어댑터입니다 :하다고

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" /> 

ㅁ y 내 목록에있는 행은 항상 내가 입력 한 것과 상관없이 동일한 크기로 설정됩니다.

답변

0

이것은 작동하지 않습니다.

귀하가해야 할 일입니다.

<?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> 

기본적으로 다른 레이아웃을 추가하고 해당 레이아웃의 높이를 지정하십시오. 루트 레이아웃의 높이를 지정하는 어댑터보기로 작업 할 때 작동하지 않습니다.

관련 문제