0

I'm inflating View for ListFragment with:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    return inflater.inflate(R.layout.fragment_home, container, false);
}

In public void onViewCreated(View view, Bundle savedInstanceState) I'm checking the view children's width/height and it seems that they are always 0. Why?

This is my fragment_home.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <FrameLayout
        android:id="@+id/home_fragment_map"
        android:layout_width="match_parent"
        android:layout_height="@dimen/home_map_h" />

    <LinearLayout
        android:id="@id/android:empty"
        android:background="@color/white"
        android:layout_width="match_parent"
        android:layout_height="@dimen/event_height"
        android:gravity="center">

        <FrameLayout
            android:layout_width="50dp"
            android:layout_height="match_parent">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/location_icon_grey"
                android:layout_gravity="center" />

        </FrameLayout>

        <com.gigaset.location.ui.custom.TextViewMuseo
            android:layout_width="match_parent"
            android:text="@string/home_no_events"
            android:layout_height="@dimen/home_latest_pos_h"
            android:gravity="center_vertical" />

    </LinearLayout>

    <ListView
        android:id="@id/android:list"
        android:divider="@null"
        android:dividerHeight="0dp"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</LinearLayout>
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Marian Paździoch
  • 8,813
  • 10
  • 58
  • 103

1 Answers1

0

Views will not take on any size until it is laid out on the screen. Aka, usually after onResume(). If you wish to obtain it's measurements when known, you can use a layout listener. For more details and an example: Android - get height of a view before it´s drawn

Community
  • 1
  • 1
Ifrit
  • 6,791
  • 8
  • 50
  • 79