web-dev-qa-db-fra.com

Impossible de redimensionner un RelativeLayout dans un ScrollView pour remplir tout l'écran

J'ai un problème étrange que je ne sais pas comment résoudre. J'ai un RelativeLayout à l'intérieur d'un ScrollView et ce scrollView a sa hauteur définie sur fill_parent. Tout comme RelativeLayout. Pourtant, le contenu ne remplit pas tout l'écran et cela ne va qu'au contenu wrap_content de la dernière mise en page à l'intérieur de ce RelativeLayout.

Voici mon code:

<RelativeLayout xmlns:Android="http://schemas.Android.com/apk/res/Android"
    xmlns:app="http://schemas.Android.com/apk/res/com.pontai"
    Android:id="@+id/relativeLayout1"
    Android:layout_width="fill_parent"
    Android:layout_height="fill_parent" >

    <ScrollView
        Android:layout_width="match_parent"
        Android:layout_height="match_parent" >

        <RelativeLayout
            Android:id="@+id/relativeLayout2"
            Android:layout_width="match_parent"
            Android:layout_height="match_parent" >

            <LinearLayout
                Android:id="@+id/linearLayout1"
                Android:layout_width="wrap_content"
                Android:layout_height="wrap_content"
                Android:layout_alignLeft="@+id/relativeLayout3"
                Android:layout_alignParentTop="true"
                Android:layout_alignRight="@+id/relativeLayout5"
                Android:layout_marginTop="5dp"
                Android:orientation="horizontal" >

                <TextView
                    Android:id="@+id/textView1"
                    Android:layout_width="wrap_content"
                    Android:layout_height="wrap_content"
                    Android:layout_gravity="center"
                    Android:text="How much points you have here:"
                    Android:textAppearance="?android:attr/textAppearanceSmall" />

                <TextView
                    Android:id="@+id/textViewTotalPoints1"
                    Android:layout_width="wrap_content"
                    Android:layout_height="wrap_content"
                    Android:layout_gravity="center"
                    Android:text="120"
                    Android:textAppearance="?android:attr/textAppearanceMedium" />
            </LinearLayout>

            <RelativeLayout
                Android:id="@+id/relativeLayout4"
                Android:layout_width="wrap_content"
                Android:layout_height="80dp"
                Android:layout_alignLeft="@+id/relativeLayout3"
                Android:layout_below="@+id/linearLayout1"
                Android:layout_marginTop="5dp"
                Android:layout_toLeftOf="@+id/textView7"
                Android:orientation="vertical" >

                <TextView
                    Android:id="@+id/textView3"
                    Android:layout_width="wrap_content"
                    Android:layout_height="wrap_content"
                    Android:layout_alignParentTop="true"
                    Android:layout_centerHorizontal="true"
                    Android:layout_marginTop="5dp"
                    Android:text="Ratings"
                    Android:textAppearance="?android:attr/textAppearanceMedium" />

                <TextView
                    Android:id="@+id/textViewPositivePoints"
                    Android:layout_width="wrap_content"
                    Android:layout_height="wrap_content"
                    Android:layout_centerHorizontal="true"
                    Android:textAppearance="?android:attr/textAppearanceSmall" />

                <ImageView
                    Android:id="@+id/imageView2"
                    Android:layout_width="25dp"
                    Android:layout_height="25dp"
                    Android:layout_below="@+id/textView3"
                    Android:layout_toLeftOf="@+id/textView3"
                    Android:src="@drawable/thumbs_up_focused" />

                <TextView
                    Android:id="@+id/textViewNegativePoints"
                    Android:layout_width="wrap_content"
                    Android:layout_height="wrap_content"
                    Android:layout_alignRight="@+id/textView3"
                    Android:layout_centerVertical="true"
                    Android:layout_marginRight="3dp"
                    Android:text="22"
                    Android:textAppearance="?android:attr/textAppearanceSmall" />

                <TextView
                    Android:id="@+id/textView5"
                    Android:layout_width="wrap_content"
                    Android:layout_height="wrap_content"
                    Android:layout_alignBaseline="@+id/textViewNegativePoints"
                    Android:layout_alignBottom="@+id/textViewNegativePoints"
                    Android:layout_alignLeft="@+id/textView3"
                    Android:layout_marginLeft="3dp"
                    Android:text="33"
                    Android:textAppearance="?android:attr/textAppearanceSmall" />

                <ImageView
                    Android:id="@+id/imageView3"
                    Android:layout_width="25dp"
                    Android:layout_height="25dp"
                    Android:layout_alignTop="@+id/imageView2"
                    Android:layout_toRightOf="@+id/textViewNegativePoints"
                    Android:src="@drawable/thumbs_down_focused" />
            </RelativeLayout>

            <RelativeLayout
                Android:id="@+id/relativeLayout5"
                Android:layout_width="95dp"
                Android:layout_height="80dp"
                Android:layout_alignRight="@+id/relativeLayout3"
                Android:layout_alignTop="@+id/relativeLayout4"
                Android:layout_toRightOf="@+id/textView7"
                Android:orientation="vertical" >

                <TextView
                    Android:id="@+id/textView4"
                    Android:layout_width="wrap_content"
                    Android:layout_height="wrap_content"
                    Android:layout_alignParentTop="true"
                    Android:layout_centerHorizontal="true"
                    Android:layout_marginTop="5dp"
                    Android:text="Comments"
                    Android:textAppearance="?android:attr/textAppearanceMedium" />

                <ImageView
                    Android:id="@+id/imageView1"
                    Android:layout_width="50dp"
                    Android:layout_height="50dp"
                    Android:layout_alignParentBottom="true"
                    Android:layout_centerHorizontal="true"
                    Android:src="@drawable/speech_bubble" />
            </RelativeLayout>

            <RelativeLayout
                Android:id="@+id/relativeLayout3"
                Android:layout_width="match_parent"
                Android:layout_height="wrap_content"
                Android:layout_below="@+id/relativeLayout4"
                Android:layout_centerHorizontal="true"
                Android:layout_marginLeft="10dp"
                Android:layout_marginRight="10dp"
                Android:layout_marginTop="10dp" >

                <TextView
                    Android:id="@+id/textViewOfferName"
                    Android:layout_width="wrap_content"
                    Android:layout_height="wrap_content"
                    Android:layout_alignParentTop="true"
                    Android:layout_centerHorizontal="true"
                    Android:layout_marginTop="10dp"
                    Android:text="Offer Name"
                    Android:textAppearance="?android:attr/textAppearanceLarge" />

                <TextView
                    Android:id="@+id/textViewBusinessName"
                    Android:layout_width="wrap_content"
                    Android:layout_height="wrap_content"
                    Android:layout_alignParentTop="true"
                    Android:layout_centerHorizontal="true"
                    Android:layout_marginTop="35dp"
                    Android:text="Business Name"
                    Android:textAppearance="?android:attr/textAppearanceMedium" />

                <TextView
                    Android:id="@+id/textViewBusinessAddress"
                    Android:layout_width="wrap_content"
                    Android:layout_height="wrap_content"
                    Android:layout_alignParentTop="true"
                    Android:layout_centerHorizontal="true"
                    Android:layout_marginTop="60dp"
                    Android:text="Business Address"
                    Android:textAppearance="?android:attr/textAppearanceMedium" />

                <TextView
                    Android:id="@+id/textViewNull1"
                    Android:layout_width="wrap_content"
                    Android:layout_height="wrap_content"
                    Android:layout_alignParentTop="true"
                    Android:layout_centerHorizontal="true"
                    Android:layout_marginTop="80dp"
                    Android:textAppearance="?android:attr/textAppearanceLarge" />

                <TextView
                    Android:id="@+id/textViewTotalPoints"
                    Android:layout_width="wrap_content"
                    Android:layout_height="wrap_content"
                    Android:layout_below="@+id/textViewNull1"
                    Android:layout_centerHorizontal="true"
                    Android:text="0/0"
                    Android:textAppearance="?android:attr/textAppearanceLarge" />

                <Button
                    Android:id="@+id/buttonUseNow"
                    Android:layout_width="wrap_content"
                    Android:layout_height="wrap_content"
                    Android:layout_below="@+id/textViewTotalPoints"
                    Android:layout_centerHorizontal="true"
                    Android:layout_marginTop="10dp"
                    Android:text="@string/offer_details_use_now" />

                <TextView
                    Android:id="@+id/textView2"
                    Android:layout_width="wrap_content"
                    Android:layout_height="wrap_content"
                    Android:layout_alignParentLeft="true"
                    Android:layout_below="@+id/buttonUseNow"
                    Android:layout_marginTop="10dp"
                    Android:text="@string/_terms_and_conditions_"
                    Android:textAppearance="?android:attr/textAppearanceSmall" />

                <TextView
                    Android:id="@+id/textViewTermsConditions"
                    Android:layout_width="wrap_content"
                    Android:layout_height="wrap_content"
                    Android:layout_alignParentLeft="true"
                    Android:layout_below="@+id/textView2"
                    Android:layout_marginTop="2dp"
                    Android:textAppearance="?android:attr/textAppearanceSmall" />
            </RelativeLayout>

            <TextView
                Android:id="@+id/textView7"
                Android:layout_width="wrap_content"
                Android:layout_height="wrap_content"
                Android:layout_alignBottom="@+id/relativeLayout5"
                Android:layout_centerHorizontal="true"
                Android:layout_marginBottom="30dp"
                Android:text="e"
                Android:textAppearance="?android:attr/textAppearanceSmall"
                Android:visibility="invisible" />
        </RelativeLayout>
    </ScrollView>

</RelativeLayout>

Quelqu'un a des idées sur la façon dont je peux faire en sorte que RelativeLayout2 ait la même hauteur que ScrollView, ce qui signifie que je veux qu'il atteigne le bas de l'écran?

Merci et salutations, Felipe

48
Felipe Caldas

J'ai déjà rencontré ce problème. Utilisez simplement Android:fillViewport="true" dans votre scrollview et il remplira l'écran.

 <ScrollView xmlns:Android="http://schemas.Android.com/apk/res/Android"
        Android:id="@+id/scrollView1"
        Android:layout_width="fill_parent"
        Android:layout_height="fill_parent"
         Android:fillViewport="true" >
149
Akhil