user3199577
user3199577

Reputation: 249

Android HorizontalScrollView width

This is my XML of the HorizontalScrollView

<HorizontalScrollView
    android:id="@+id/horizontalScrollView1"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="19" >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:orientation="horizontal" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/card_background" >

        </RelativeLayout>

    </LinearLayout>
</HorizontalScrollView>

I want to set the width of the RelativeLayout equal to the width of the HorizontalScrollView. How can I do this with XML (not programmatically)

Upvotes: 2

Views: 5370

Answers (2)

Mikel
Mikel

Reputation: 1621

All you are missing for what you want is in the HorizontalScrollView

android:fillViewport="true"

Upvotes: 11

nKn
nKn

Reputation: 13761

I'd define the width you want to set to the RelativeLayout and set the HorizontalScrollView's width and height to wrap_content. This way it's not the HorizontalScrollView who's defining the width, it just wrap it.

Upvotes: 1

Related Questions