开发者

horizontalscrollview set child elements to fill horizontalscrollview width

Basically I have a horizontal scroll view which, by monitoring the onTouch event I'm paging (ie:each visible part of the scroll view (page) "clicks" into the next when scrolling, rather than just having a standard ScrollView. see paged scrollviews in iOS).

Now I want to find a way to have inner children inherit the same width as the scrollview (which is set at "fill_parent").

Here is my XML to help:

<HorizontalScrollView
        android:id="@+id/scrollview"
        android:layout_height="0dp" 
        android:layout_width="fill_parent"
        android:layout_weight="1"
        android:background="@drawable/scrollviewbg">

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

            <ImageView
                android:src="@drawable/content1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
            开发者_运维问答<ImageView
                android:src="@drawable/content2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
            <ImageView
                android:src="@drawable/content3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

        </LinearLayout>

    </HorizontalScrollView>

As you can see the scrollview is set to width fill_parent and there is a LinearLayout inside it. Now at the moment there are three images which have a set width and height similar to the width of the screen, but what I want to do is change that for 3 LinearLayouts.

Each LinearLayout needs to inherit the same width as the scroll view, so that each one takes up a whole "page" when my code is applied, as it were.

How would I do this? Is it something I will have to do using code? What code will I need?

Thank you.


I know its not direct answer, but its much easier to user ViewPager from Compatibility Package for paging functionality. You can find an example in samples folder (see src/com/example/android/supportv4/app/FragmentPagerSupport.java for source code).


Try this: android:fillViewport="true"

<HorizontalScrollView

    android:fillViewport="true"

    android:layout_width="match_parent"
    android:layout_height="wrap_content">
<TextView
    android:layout_gravity="right"
    android:background="@drawable/black_border"
    android:id="@+id/displayText"
    android:layout_width="match_parent"
    android:scrollHorizontally="true"
    android:layout_height="wrap_content"
    android:gravity="right"
    android:padding="20dp"
    android:text=""
    android:textSize="20sp" />
</HorizontalScrollView>

inside horizontal scroll view, i have a text view, you can try for image view


Set all the layout_height parameters as fill_parent. You should see the image in full screen then.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜