2011-08-29 118 views
3

基本上我有一个水平滚动视图,通过监视onTouch事件我正在分页(即:滚动视图(页面)的每个可见部分“点击”滚动到下一个,而不仅仅是具有标准的ScrollView。请参阅iOS中的分页滚动视图)。horizo​​ntalscrollview设置子元素来填充horizo​​ntalscrollview的宽度

现在我想找到一种方法来让内部子代继承与滚动视图相同的宽度(设置为"fill_parent")。

这里是我的XML的帮助:

<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> 

正如你可以看到滚动视图设置为宽度fill_parent并且里面有它LinearLayout。现在有三个图像的宽度和高度与屏幕宽度相似,但我想要做的是更改为3 LinearLayout s。

每个LinearLayout都需要继承与滚动视图相同的宽度,这样当我的代码被应用时,每个代码都会占用整个“页面”。

我该怎么做?这是我将不得不使用代码吗?我需要什么代码?

谢谢。

回答

3

我知道它没有直接的答案,但对于寻呼功能来说,它更容易从Compatibility Package用户ViewPager。您可以在samples文件夹中找到示例(有关源代码,请参阅src/com/example/android/supportv4/app/FragmentPagerSupport.java)。

+0

是容易得多。感谢那。 :) –

+0

我没有该选项使用支持库,我们可以在scrollview中执行 – user606669

0

将所有layout_height参数设置为fill_parent。你应该在全屏幕中看到图像。

+1

错误!当将子视图添加到“Horizo​​ntalScrollView”时,“fill_parent”没有意义。 – neevek

0

试试这个: 机器人:fillViewport = “真”

<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> 

水平滚动视图中,我有一个文本视图,你可以尝试图像视图