0

这是我的主要布局:

<RelativeLayout style="@style/StandardFillWrap" >

    <TableLayout
        android:id="@+id/match_tab"
        style="@style/StandardFillWrap"
        android:stretchColumns="*" >

        <TableRow >

            <TextView android:id="@+id/match_home_name" />

            <TextView android:id="@+id/match_home_score" />
        </TableRow>

        <TableRow >

            <TextView android:id="@+id/match_away_name" />

            <TextView android:id="@+id/match_away_score" />
        </TableRow>
    </TableLayout>

    <Button
        android:id="@+id/match_filter_b"
        style="@style/StandardFillWrap"
        android:layout_below="@id/match_tab"
        android:text="@string/l_matchView_filters" />

    <LinearLayout android:id="@+id/match_list"
        style="@style/StandardWrapWrap" 
        android:layout_below="@id/match_filter_b"
        />
    <TableLayout
        android:id="@+id/match_reparti"
        style="@style/StandardFillWrap"
        android:layout_below="@id/match_list"
        android:stretchColumns="*" >

        <TableRow >

            <TextView
                android:id="@+id/match_home_name_det"
                style="@style/NomePlayer"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" />

            <TextView android:text="@string/vuoto" />
        </TableRow>

        <TableRow >

            <TextView android:text="@string/l_matchView_indirect_set_pieces" />

            <TextView android:text="@string/vuoto" />
        </TableRow>

        <TableRow >

            <TextView android:text="@string/l_matchView_defence" />

            <TextView android:id="@+id/match_home_set_def" />
        </TableRow>

        <TableRow >

            <TextView android:text="@string/l_matchView_attack" />

            <TextView android:id="@+id/match_home_set_att" />
        </TableRow>

        <TableRow >

            <TextView android:text="@string/vuoto" />

            <TextView android:text="@string/vuoto" />
        </TableRow>

        <TableRow >

            <TextView android:text="@string/l_matchView_team_attitude" />

            <TextView android:id="@+id/match_home_team_attitude" />
        </TableRow>

        <TableRow >

            <TextView android:text="@string/l_matchView_tactic" />

            <TextView android:id="@+id/match_home_team_tactic" />
        </TableRow>

        <TableRow >

            <TextView android:text="@string/l_matchView_tactic_skill" />

            <TextView android:id="@+id/match_home_team_tactic_skill" />
        </TableRow>

        <TableRow >

            <TextView android:text="@string/vuoto" />

            <TextView android:text="@string/vuoto" />
        </TableRow>

        <TableRow >

            <TextView android:text="@string/l_matchView_midfield" />

            <TextView android:id="@+id/match_home_team_midfield" />
        </TableRow>

        <TableRow >

            <TextView android:text="@string/l_matchView_right_defence" />

            <TextView android:id="@+id/match_home_team_r_def" />
        </TableRow>

        <TableRow >

            <TextView android:text="@string/l_matchView_central_defence" />

            <TextView android:id="@+id/match_home_team_c_def" />
        </TableRow>

        <TableRow >

            <TextView android:text="@string/l_matchView_left_defence" />

            <TextView android:id="@+id/match_home_team_l_def" />
        </TableRow>

        <TableRow >

            <TextView android:text="@string/l_matchView_right_attack" />

            <TextView android:id="@+id/match_home_team_r_att" />
        </TableRow>

        <TableRow >

            <TextView android:text="@string/l_matchView_central_attack" />

            <TextView android:id="@+id/match_home_team_c_att" />
        </TableRow>

        <TableRow >

            <TextView android:text="@string/l_matchView_left_attack" />

            <TextView android:id="@+id/match_home_team_l_att" />
        </TableRow>

        <TableRow >

            <TextView
                android:id="@+id/match_away_name_det"
                style="@style/NomePlayer"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" />

            <TextView android:text="@string/vuoto" />
        </TableRow>

        <TableRow >

            <TextView android:text="@string/l_matchView_indirect_set_pieces" />

            <TextView android:text="@string/vuoto" />
        </TableRow>

        <TableRow >

            <TextView android:text="@string/l_matchView_defence" />

            <TextView android:id="@+id/match_away_set_def" />
        </TableRow>

        <TableRow >

            <TextView android:text="@string/l_matchView_attack" />

            <TextView android:id="@+id/match_away_set_att" />
        </TableRow>

        <TableRow >

            <TextView android:text="@string/vuoto" />

            <TextView android:text="@string/vuoto" />
        </TableRow>

        <TableRow >

            <TextView android:text="@string/l_matchView_team_attitude" />

            <TextView android:id="@+id/match_away_team_attitude" />
        </TableRow>

        <TableRow >

            <TextView android:text="@string/l_matchView_tactic" />

            <TextView android:id="@+id/match_away_team_tactic" />
        </TableRow>

        <TableRow >

            <TextView android:text="@string/l_matchView_tactic_skill" />

            <TextView android:id="@+id/match_away_team_tactic_skill" />
        </TableRow>

        <TableRow >

            <TextView android:text="@string/vuoto" />

            <TextView android:text="@string/vuoto" />
        </TableRow>

        <TableRow >

            <TextView android:text="@string/l_matchView_midfield" />

            <TextView android:id="@+id/match_away_team_midfield" />
        </TableRow>

        <TableRow >

            <TextView android:text="@string/l_matchView_right_defence" />

            <TextView android:id="@+id/match_away_team_r_def" />
        </TableRow>

        <TableRow >

            <TextView android:text="@string/l_matchView_central_defence" />

            <TextView android:id="@+id/match_away_team_c_def" />
        </TableRow>

        <TableRow >

            <TextView android:text="@string/l_matchView_left_defence" />

            <TextView android:id="@+id/match_away_team_l_def" />
        </TableRow>

        <TableRow >

            <TextView android:text="@string/l_matchView_right_attack" />

            <TextView android:id="@+id/match_away_team_r_att" />
        </TableRow>

        <TableRow >

            <TextView android:text="@string/l_matchView_central_attack" />

            <TextView android:id="@+id/match_away_team_c_att" />
        </TableRow>

        <TableRow >

            <TextView android:text="@string/l_matchView_left_attack" />

            <TextView android:id="@+id/match_away_team_l_att" />
        </TableRow>
    </TableLayout>
</RelativeLayout>

填充方法match_list是:

private void mimicListAdapter(List<Event> eventsList, String filters) {

    TextView minute;
    ImageView event_key;
    TextView event_text;
    LayoutInflater inflater = getLayoutInflater();
    LinearLayout container = (LinearLayout) findViewById(R.id.match_list); 

    for(Event p:eventsList) {
        //LayoutInflater inflater = getLayoutInflater();
        View rowView = inflater.inflate( R.layout.match_event, null, true);
        minute = (TextView) rowView.findViewById(R.id.minute);
        event_key = (ImageView) rowView.findViewById(R.id.event_img);
        event_text = (TextView) rowView.findViewById(R.id.event_text);
        boolean found = false;
        String[] events = getResources().getStringArray(R.array.filtering);
        if(filters!=null)
        {
            if(filters!="")
            {
                char[] indici = filters.toCharArray();
                for(int i = 0; i<indici.length; i++){
                    if(events[Character.getNumericValue( indici[i] )].contains(","+p.getEventKey()+","))
                    {
                        found=true;
                        break;
                    }
                }   
            }

        }
        minute.setText(Integer.toString(p.getMinute()));
        event_text.setText(p.getEventText());
        try {
            Drawable img = getResources().getDrawable( getResources().getIdentifier("i_"+p.getEventKey(), "drawable", getPackageName()));
            event_key.setImageDrawable(img);
        } catch (Exception e) {

        }

        if(found) {
            event_text.setTextColor(0xFFFF0000);
            minute.setTextColor(0xFFFF0000);
            found = false;
        }   

        container.addView(rowView);
    }
}

我遇到的问题是外部match_list的任何内容都正确显示,在 match_list 内部我可以看到第一个元素,但是它都是空白的。我的意思是 che LinearLayout 似乎被填满了,因为它占据了很多显示器,但它只是黑色空间,只有第一个Event可见。

4

2 回答 2

1

向容器添加视图时,您应该使用 LayoutParams 类传递有关必须如何显示它的信息。现在,您缺少在布局 xml 中使用 layout_widht 和 layout_height 定义的信息。如果没有它们,我猜Android会设置第一个视图,但由于缺少大小信息而无法对齐其他视图。像这样的东西:

container.addView(rowView, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
于 2012-03-19T22:15:01.603 回答
0

我真的是个白痴。我错过了 LinearLayout 的垂直方向。

顺便说一句,我发现听了这个关于 ListView 的 Google I/O。http://www.youtube.com/watch?v=wDBM6wVEO70

于 2012-03-20T01:34:08.980 回答