开发者

How to display a custom view in Android?

开发者 https://www.devze.com 2023-01-14 07:36 出处:网络
I am generating a custom View that contains a number of drawables that are added to the View dynamically. This means the View\'s size could be anything, and is likely to stretch off the screen. Where

I am generating a custom View that contains a number of drawables that are added to the View dynamically. This means the View's size could be anything, and is likely to stretch off the screen. Where it does stretch off the screen I want scrolling to be enabled.

So far I have tried:

  • adding the custom view directly to my Activity - this displays the drawables ok, but with no scrolling
  • adding the custom view as a child to a ScrollView and setting the ScrollView as the content in the Activity - this doesn't display anything.

How do I generate a custom view of arbitrary size, displ开发者_JAVA百科ay it and have scrolling where it is too big for the screen?


Adding it to a ScrollView should be fine. Remember:

A ScrollView is a FrameLayout, meaning you should place one child in it containing the entire contents to scroll; this child may itself be a layout manager with a complex hierarchy of objects. A child that is often used is a LinearLayout in a vertical orientation, presenting a vertical array of top-level items that the user can scroll through.

To make sure your "custom view" is working fine, first try to add a LinearLayout to the ScrollView and then add drawables to the LinearLayout.

0

精彩评论

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

关注公众号