The Thom The Thom - 2 months ago 7
Android Question

Why is the bottom of my fragment not displaying?

I created the following DialogFragment in XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@id/mainLayout"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="5dp"
android:paddingRight="0dp"
android:orientation="vertical" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@id/quoteLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="5dp"
android:paddingRight="0dp"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@id/buttonLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="5dp"
android:paddingRight="0dp"
android:orientation="vertical" >
<Button
android:id="@id/getMoreButton"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/getMore"
android:onClick="getMore" />
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@id/adLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="5dp"
android:paddingRight="0dp"
android:orientation="vertical" >
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
</LinearLayout>
</LinearLayout>


I've been working along on the quoteLayout section and have it performing as I wish. Now I wanted to fill the other sections with a button and an ad.

The problem is that nothing still shows up in the other parts of the mainLayout. The end of the screen is the end of the quoteLayout.

Any ideas?

Answer

You have it orientation set as vertical but in your linearlayout children you have the android:layout_height attribute as match_parent which fills up the layout. It should be wrap_content or use weights to better organize how it should look. At least, that's what looks wrong to me. Try swapping out match_parent to wrap_content or use weight attribute.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@id/mainLayout"
          xmlns:ads="http://schemas.android.com/apk/res-auto"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:paddingLeft="5dp"
          android:paddingRight="0dp"
          android:orientation="vertical" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@id/quoteLayout"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:paddingLeft="5dp"
              android:paddingRight="0dp"
              android:orientation="vertical" >
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@id/buttonLayout"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:paddingLeft="5dp"
              android:paddingRight="0dp"
              android:orientation="vertical" >
    <Button
        android:id="@id/getMoreButton"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="@string/getMore"
        android:onClick="getMore" />
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@id/adLayout"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:paddingLeft="5dp"
              android:paddingRight="0dp"
              android:orientation="vertical" >
    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        ads:adSize="BANNER"
        ads:adUnitId="@string/banner_ad_unit_id">
    </com.google.android.gms.ads.AdView>
</LinearLayout>

Comments