3

I need to implement a View, containing a RelativeLayout.

  • The Width and Height of the parent should be absolute values.
  • The child's Width and Height are either set to WRAP_CONTENT or an absolute value, but never to MATCH_PARENT.
  • The child may be larger than the parent. If this is the case, only the part of the RelativeLayout which fitted in the parent View, should be visible, as in the picture below.

The parent View (black) and the child View (red)
Also, the RelativeLayout should be able to be moved and therefor change the visible part in the parent View. Unfortunately, Android doesn't let me do this. The child is allways clipped down to fit inside the parent.
I stumbled across ScrollView and HorizontalScrollView allready, but they allow the user to scroll around and that's not what I want him to be able to. There's just this too big RelativeLayout of which I want to show the user a just a part of.

Everything is added to the screen programmatically, without XML.

Is it possible? Maybe I haven't seen some obvios possibilities with ScrollView?

EarlGrey
  • 531
  • 7
  • 29

2 Answers2

1

As you suggest you can use a ScrollView and disable scrolling in this view.

To do this read this answer:

Disable ScrollView Programmatically?

;)

Community
  • 1
  • 1
axl coder
  • 739
  • 3
  • 19
  • Oh...Maybe I'll give ScrollView another try. Thanks! – EarlGrey Jul 04 '14 at 13:47
  • But as I need twodimensional scrolling, I had to nest HorizontalScrollView into ScrollView. Where do I have to call scrollTo() on? One or both? – EarlGrey Jul 04 '14 at 13:50
  • cit. I stumbled across ScrollView and HorizontalScrollView allready, but they allow the user to scroll around and that's not what I want him to be able to. LOL...Do you need scroll or not???? – axl coder Jul 04 '14 at 14:05
  • I need to scroll, because the desired part of the child View isn't necessarily the top left corner. It's the user who has to be unable to scroll. – EarlGrey Jul 07 '14 at 07:35
  • You have to override onGestureDetector and find out in whic way the user is scrolling your view. If the user scroll in horizontal direction then your HorizontalScrollView will capture the the swipe, otherwise if he scroll in vertical direction the gesture will be managed by your scrollview. This answer is a good start point http://stackoverflow.com/questions/19411518/two-dimensional-scrolling-a-suggestion-that-needs-feedback – axl coder Jul 07 '14 at 15:24
0

Try to set layout's clipChildren:false

http://developer.android.com/reference/android/view/ViewGroup.html#attr_android:clipChildren

Peter Zhao
  • 7,456
  • 3
  • 21
  • 22
  • 1
    I tried this already and it didn't work. As of I'm adding my stuff programmatically, I used the parent View's setClipChildren(false) – EarlGrey Jul 04 '14 at 13:40