Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
274 views
in Technique[技术] by (71.8m points)

android - How to generate copies of LinearLayout in java inside loop

I want to know how could I copy a particular LinearLayout like this:

<LinearLayout
    android:id="@+id/someID"
    android:layout_width="match_parent"
    android:layout_height="520dp"
    android:layout_marginBottom="25dp"
    android:background="@drawable/corner_rounder"
    android:orientation="vertical">
</LinearLayout>

Inside Java code using for loop. I need such a solution to dynamically generate content depending on its quantity. This LinearLayout is inside ScrollView.

question from:https://stackoverflow.com/questions/65930909/how-to-generate-copies-of-linearlayout-in-java-inside-loop

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You Cant do like this!

Try With RecyclerView with custom LinearLayout and Adapter!

Take a ArrayList for indexing LinearLayout if you need new LinearLayout just programmatically add a value in your ArrayList and bang there will be a new LinearLayout in your RecyclerViewand thats how you can add as many as you want !


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...