在android中动态查找和复制视图?
我现在已经创建了一个视图,我只想一个接一个地复制这个视图在android中动态查找和复制视图?,android,view,android-linearlayout,Android,View,Android Linearlayout,我现在已经创建了一个视图,我只想一个接一个地复制这个视图 说 现在我想在一个线性布局中一个接一个地动态复制这个,比如说 <LinearLayout android:id="@+id/comp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="top" android:orien
说
现在我想在一个线性布局中一个接一个地动态复制这个,比如说
<LinearLayout
android:id="@+id/comp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="top"
android:orientation="vertical" >
</LinearLayout>
我怎样才能做到这一点呢?使用
和/或
。请参阅有关在Android SDK中重用布局的Android布局提示:
LinearLayout parent = (LinearLayout)findViewById(R.id.item);
in loop
LinearLayout child = getLayoutInflater().inflate(R.layout.child);
// fill in any details dynamically here
TextView textView = (TextView) v.findViewById(R.id.txtComp1_Brand);
textView.setText("text");
parent .addView(LinearLayout);
嗯,我相信关键词是复制,不是膨胀。膨胀是一个相当昂贵和耗时的过程,而复制是简单和快速的。两个链接都失效了。
LinearLayout parent = (LinearLayout)findViewById(R.id.item);
in loop
LinearLayout child = getLayoutInflater().inflate(R.layout.child);
// fill in any details dynamically here
TextView textView = (TextView) v.findViewById(R.id.txtComp1_Brand);
textView.setText("text");
parent .addView(LinearLayout);