1

I want to set a ScrollView for some views. I need to merge some view into one view and add to ScrollView.

The three views are listView, custorm view and Gallery.

Who knows how to merge the three views into a blank view and display?

DaringLi
  • 409
  • 2
  • 6
  • 16

2 Answers2

0

In XML you can structure your app like the following snippet:

<ScrollView>
    <LinearLayout>
        <CustomView/>
        <ListView/>
        <Gallery/>    
    </LinearLayout>
</ScrollView>

Alternatively in code, you can do it like so:

ScrollView SV = (ScrollView) findViewById(R.id.my_scrollview);

LinearLayout LL = (LinearLayout) findViewById(R.id.my_linear_layout);
LL.addView(my_customView)
LL.addView(my_istView)
LL.addView(my_gallery)

SV.addView(LL);

hope that gives you some pointers in how to achieve what you'd like to

Matt Taylor
  • 3,360
  • 1
  • 20
  • 34
0

You can create those objects and assign them inflated elements. I mean, if the listView is in listView.xml you can inflate it with getLayoutInflater().inflate(R.layout.listView,null) and put in a ListView object. Then you can add it to a ViewGroup.

Inflate the ScrollView, you can create programmatically too. ScrollView scroll=new ScrollView(this). Don't forget adding LayoutParams to the view if you do it programmatically.

ViewGroup scrollView = (ViewGroup) getLayoutInflater().inflate(R.layout.scrollView, null);

Then you inflate or create the other views the same way. Or you can get it from an activity with findViewById(R.id.idOfView1).

Finally just add the views you've created, inflated... with scrollView.addView(View child).

You need a ViewGroup to add views as childs.

Jon Zangitu
  • 957
  • 1
  • 15
  • 30