【问题标题】:LinearLayout addView with index error带有索引错误的LinearLayout addView
【发布时间】:2013-07-02 11:46:15
【问题描述】:

在 ScrollView 中,我有一个 LinearLayout。在此 LinearLayout 中,我无法添加带索引的视图。

为什么?

示例:

RelativeLayout relativeLayout = (RelativeLayout) getLayoutInflater().inflate(R.layout.android_messenger_sent_message, null);
TextView inbox_message = (TextView)relativeLayout.findViewById(R.id.sentMessage);
inbox_message.setText(conversationInfo.getBody()+" "+conversationInfo.getId());
linearLayoutGlobal.addView(relativeLayout,i);

i 是从 1 000 000 开始的整数,并且它越来越小

【问题讨论】:

    标签: android android-linearlayout


    【解决方案1】:

    如果没有视图,您无法添加到位置 1 000 000。 :) 尝试使用addView(relativeLayout) 而不是索引版本。

    如果您需要以相反的顺序添加,请使用addView(relativeLayout, 0)。这将继续插入列表的头部,因此,将区域添加的视图抛在后面。

    注意:将 1M 视图添加到单个滚动视图肯定会失败,因为您的资源已用完。尝试使用较小的数字或更改为ListView

    【讨论】:

    • 这并不能完全解决我的问题,但我使用它并在这里和那里更改了一些代码。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-03
    • 2014-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多