android – 在horizo​​ntalScrollView中的布局是屏幕的大小

前端之家收集整理的这篇文章主要介绍了android – 在horizo​​ntalScrollView中的布局是屏幕的大小前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我是 Android的新手,一直在寻找一个解决方案,但到目前为止没有运气.我想创建一个类似下面的图片的布局.

我想要一个linearLayout是屏幕的大小.然后有另一个linearLayout也是屏幕的大小,但关闭屏幕.我可以在两个虚拟“屏幕”之间滚动. (我要显示图像,但是,由于我是新的网站,我不被允许…链接到图像是here

有一篇有趣的文章解释了如何扩展scrollView类,以便我可以得到一个很酷的捕捉效果,所以如果我可以得到这个工作,我的应用程序将感觉很像在主屏幕之间滚动.

我已经阅读了关于权重,还有关于scrollView的fillViewport =“true”.我恐怕我不明白如何使用horizo​​ntalScrollView来让linearLayouts填满屏幕.我尝试过各种各样的fill_parent和wrap_content的组合,但是没有用.

正如我所看到的那样,只要我构建子视图(每个“屏幕”中的元素),并考虑到屏幕变异性,这个功能就不会影响应用在具有不同屏幕的设备之间的可移植性.

以下是我正在尝试的XML的简单示例:

  1. <HorizontalScrollView
  2. xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:id="@+id/HorizontalScrollView01"
  4. android:layout_width="wrap_content"
  5. android:layout_height="wrap_content"
  6. android:fillViewport="true">
  7.  
  8. <LinearLayout
  9. android:orientation="horizontal"
  10. android:layout_width="fill_parent"
  11. android:layout_height="fill_parent">
  12.  
  13. <LinearLayout
  14. android:orientation="vertical"
  15. android:layout_width="fill_parent"
  16. android:layout_height="fill_parent">
  17.  
  18. <EditText
  19. android:layout_width="fill_parent"
  20. android:layout_height="fill_parent"
  21. android:id="@+id/txtTestBox"
  22. >
  23. </EditText>
  24. </LinearLayout>
  25.  
  26. <LinearLayout
  27. android:orientation="vertical"
  28. android:layout_width="fill_parent"
  29. android:layout_height="wrap_content">
  30.  
  31. <Button
  32. android:layout_width="fill_parent"
  33. android:layout_height="wrap_content"
  34. android:text="Button 1"
  35. />
  36.  
  37. </LinearLayout>
  38.  
  39. </LinearLayout>
  40.  
  41. </HorizontalScrollView>

不幸的是,这甚至没有接近我正在寻找的东西.希望这可以做到…

感谢任何帮助或建议.

解决方法

水平滚动视图可以无限地缩放到一边,所以“填充父”很可能不会像您在内部布局中所期望的那样工作.您是否尝试在内部布局上明确指定宽度?

就像是:

  1. <HorizontalScrollView
  2. xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:id="@+id/HorizontalScrollView01"
  4. android:layout_width="wrap_content"
  5. android:layout_height="wrap_content"
  6. android:fillViewport="true">
  7.  
  8. <LinearLayout
  9. android:orientation="horizontal"
  10. android:layout_width="400dp"
  11. android:layout_height="fill_parent">
  12.  
  13. .....
  14.  
  15. </LinearLayout>
  16.  
  17.  
  18. </HorizontalScrollView>

猜你在找的Android相关文章