开发者

Scrolling Layouts with buttons!

开发者 https://www.devze.com 2023-03-09 05:00 出处:网络
I am trying to make a scrollable layout that contains many relativelayouts and button. (See example below). But every time i make a scrollview it says a scroll view can on contain one child...

I am trying to make a scrollable layout that contains many relativelayouts and button. (See example below). But every time i make a scrollview it says a scroll view can on contain one child...

EXAMPLE

Scrollview

Relativelayouts1
    Button1
Relativelayouts2
    Button2
Relativelayouts3
    Button3
Relativelayouts4
    Button4

Scrollvie开发者_如何学Pythonw (END)


The solution to this is simple... Wrap the child layouts with a single layout. For example, something like the following.

ScrollView
    LinearLayout
        Relativelayouts1
            Button1
        Relativelayouts2
            Button2
        Relativelayouts3
            Button3
        Relativelayouts4
            Button4


Why would you want to have 4 RelativeLayouts? It defeats the purpose of that layout. Most probably, you can get the same result using:

<ScrollView>
  <RelativeLayout>
    <Button/>
    <Button/>
    <Button/>
    <Button/>
  </RelativeLayout>
</ScrollView>

This way you avoid wasting precious resources generating useless Views.

Take your time to read this post: http://www.curious-creature.org/2009/02/22/android-layout-tricks-1/ (and parts 2 and 3 also)

0

精彩评论

暂无评论...
验证码 换一张
取 消