Reputation: 1683
I'm using the following XML file for creating a layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widget28"
android:layout_width="fill_parent"
android:layout_height="80px">
<LinearLayout
android:id="@+id/linearText"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_marginLeft="10px"
android:layout_marginTop="10px">
<TextView
android:id="@+id/txtAirLineCodeLv"
android:text="TextView" />
<ImageView
android:id="@+id/StopDetailBtnLv"/>
<TextView
android:id="@+id/txtPriceLv"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/imgFlightLogoLv" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/txtTotalDurationLv"
android:text="TextView" />
<TextView
android:id="@+id/txtStopCountLv"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/txtOrgLv"
android:text="TextView" />
</LinearLayout>
</LinearLayout>
But when I load this file by using a following code:
view = context.LayoutInflater.Inflate(Resource.Layout.CustomizeSearchResult, parent, false) as LinearLayout;
a RuntimeException
is thrown. I think I have problem in the layout but I'm not able to find that. Because when I load another XML file in place of that, then no error is showed and it run successfully.
Upvotes: 1
Views: 149
Reputation: 21191
Here you did not set the height
and weight
to the ImageView
and TextView
.
Graphic layout will be visible to you if you give proper height and weight
to the UI Elements.
If you want to set the height and weight to the UI elements programmatically, you can set the height and weight using java. You need not worry about the sizes given in the XML
layout.
I am sure these height and weight will be changed at runtime.
change your xml as like this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widget28"
android:layout_width="fill_parent"
android:layout_height="80px">
<LinearLayout
android:id="@+id/linearText"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_marginLeft="10px"
android:layout_marginTop="10px">
<TextView
android:id="@+id/txtAirLineCodeLv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<ImageView
android:id="@+id/StopDetailBtnLv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/txtPriceLv"
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/imgFlightLogoLv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:id="@+id/linearText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/txtTotalDurationLv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="@+id/txtStopCountLv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/txtOrgLv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
</LinearLayout>
Upvotes: 1
Reputation: 6578
You forgot to specify the layout_height and layout_width for TextViews and ImageView
Upvotes: 1