I have a custom view that I'm using canvas to be able to draw on it what I want, this view inside a scrollview that take match_parent for each width and height and also my custom view take match_parent for each width and height
I want to know the size of the scrollview to be able to draw only inside the available space that I have
I have tried onLayout, onMeasure but nothing works with me
Can any one please help?
I have solved this problem using
onGlobalLayout Method, and I also inherit Viewgroup not View and implement onLayoutMethod, to make element shown in my fragement
Thanks all
Related
I am new to Android and currently having some issues with layout. Here is my problem:
View view = (View)findViewById(R.id.MiddleMan);
view.layout(240,358,240+view.getWidth(),358+view.getHeight());
width is 2 dp, height is match_parent. This view is inside a relative_layout, which is inside a linear_layout. This coordinates are relative to linear_layout
When I run, instead of being exactly at this coordinate, it keeps sticking to the right edge of the parent. Can anyone show me how I can deal with this problem, pls ? Appreciate a lot
Good afternoon,
I am trying to programmatically scroll a ScrollView that holds a view container that is larger than the ScrollView in true size. However the ScrollView needs to cut off the container at a predetermined size. So if the ScrollView height is 600px and the container size is 1000px then I need access to the 1000px so I can scroll fluidly programmatically. This issue was solved on github for another developer here but this doesn't seem to be working for me. Here is what I have tried:
<ScrollView>
<View onLayout={(event) => {console.log(event.nativeEvent.layout);}>
...
</View>
</ScrollView>
Attempt 1: Put an onLayout callback in both the scrollView and the inner View and use the innerViews layout height.
Result: This didn't work both the ScrollView and inner View are reporting a height of 600.
Attempt 2: Save reference to the ScrollView and then call RCTUIManager's measure function at a later point like so:
RCTUIManager.measure(this.refs.scrollView.getInnerViewNode(), (...data)=>{console.log(data)});
Result: This didn't work either, the innerViewNode is reporting a container height (4th parameter in data) of 600 again.
Anyone have a difference solution to receiving the container height? I am definitely putting a 1000ish px view within a 600ish px scroll view and when I scroll programmatically say 100px, I can see that the content is actually bigger than the ScrollView wrapper.
Thanks for any help anyone can provide!
Here is a solution I found to work:
<ScrollView>
{{...components of variable length...}}
<View key="bottomMarker" onLayout={() => {console.log(event.nativeEvent.layout.y)}}></View>
</ScrollView>
By using the View as a marker for the bottom, you can find the location of the bottom of the scroll view.
I want to create a custom diagonal layout like androids predefined linear layout..so i started with a class extending ViewGroup and overrided OnLayout and OnMeasure methods..However I am finding it difficult to understand where to write the logic for alligning all the Views such that they will be placed diagonally
I read few blogs on it How to Create Custom Layout in Android by Extending ViewGroup Class
Also followed the google I/O video
But still not clear about how to get started with creating a diagonal layout..can someone suggest any additional resources in this regard..???
The logic to measure children should be in onMeasure. In here, you want the sum of all children height to be as big as the height given in the heightMeasureSpec. Same goes for the width.
To do so, you can divide the width and height from measureSpec by the number of children, and call the child views measure method with those computed values.
The logic to position the children is in onLayout. In here, you call the child views layout method one after another, passing it positions (left, top, ...) incremented after layouting each child.
You must take care of child views margins in both methods, as well as your container padding.
Lucas Rocha has a very good article (with lot of reverse engineering) for custom views.
I have a custom View I'm making which has a fixed proportion between width and height. I want the programmer to set the height and I would like the View to set its own width according to a formula based on height.
The View is going to be a child of a RelativeLayout so I can't use the height of the parent element to calculate anything.
How can I accomplish this? I don't know how to do it in the onMeasure hook because the View's width and height are not available at that time.
By the way, I am making this view solely programmatically, no XML involved.
use View.setlayoutParams()
There's an example using an adView here.
i have a scroll view, that has a relative layout in it. the content of this scrollview varies, and you may not get the full content at first time.
example, at time 0, onCreate completely executed, current height is 500dip, but at time 5, because some items in the content is fetching results asynchronously, once completed, it will display the result, so at time 5, the height of the content in scroll view can become 600dip
my goal is to have an overlay on top of the content in the scroll view, which should cover the view entirely i.e. height should be the same.
because the height can grow at any size, at different time, i don't think i can set height of the overlay to match_parent
how can i do this in android?
is there a method where i can get notified when the scroll view or relativelayout 's height is growing?? so that whenever it is updated to a larger height, i can change my overlay's height dynamically as well..?
any other method i can consider too
thanks!!
ScrollView inherits from FrameLayout and FrameLayout has an onSizeChanged() method. I would extend ScrollView and override that method so you can capture size changes. This might work for you.