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 LinearLayout
s.
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).