When does the size of a view update during an activity?
I've been trying to get one view to update its size to a fraction of a different view's when an activity launches. I am able to get the measurement of the larger view within its own class, but I'm having trouble passing that value across to the smaller view. Three approaches I've tried so far are:
Using some combination of layout weight, but this doesn't seem accurate to me (unless I'm missing something about the values)
I have tried within the larger view's class to assign a size to the smaller view, but my app crashes when launched using this method.
When I use a getWidth() function referencing that object within the layout, my log tells me the value is 0. Currently I've tried calling this during onCreate and onStart, but it seems like this runs prior to the view being drawn as the value is still 0. Is there some other method I should interrupt in the activity in order to colle开发者_如何学Goct this value?
Thanks and if I can provide any other info that would better clarify, let me know.
Layout_weight should work for you. For example if you want view_one to be half the width of view_two it would look like this.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<View
android:id="@+id/view_one"
android:layout_height="wrap_content"
android:layout_width="0dp"
andoird:layout_weight="1" />
<View
android:id="@+id/view_two"
android:layout_height="wrap_content"
android:layout_width="0dp"
andoird:layout_weight="2" />
</LinearLayout>
精彩评论