我是 android 的新手,一直在寻找解决方案,但到目前为止还没有成功。我想创建一个类似于下图的布局。
我想要一个与屏幕大小相同的 linearLayout。然后有另一个与屏幕大小相同但在屏幕外的 linearLayout。然后我可以在两个虚拟“屏幕”之间滚动。
有一篇有趣的文章解释了如何扩展 scrollView 类,以便我可以获得很酷的捕捉效果,所以如果我可以让它工作,我的应用程序会感觉很像在主屏幕之间滚动。
我已经阅读了有关权重以及 scrollView 的 fillViewport="true"的内容。恐怕我不明白如何将它们与 horizontalScrollView 一起使用以使 linearLayouts 填满屏幕。我尝试了 fill_parent 和 wrap_content 的各种组合,但都无济于事。
在我看来,只要我在构建 subview (每个“屏幕”中的元素)时考虑到屏幕可变性,此功能就不会损害应用程序在具有不同屏幕的设备之间的可移植性。
这是我正在尝试的 XML 的一个简单示例:
<HorizontalScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/HorizontalScrollView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fillViewport="true">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/txtTestBox"
>
</EditText>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button 1"
/>
</LinearLayout>
</LinearLayout>
</HorizontalScrollView>
不幸的是,这甚至与我正在寻找的东西相去甚远。希望这可以做到...
感谢任何帮助或建议。
最佳答案
See here解决方案是使用 android:fillViewport="true"
在 ScrollView.
上无需固定 LinearLayout 宽度。
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:fillViewport="true"
android:orientation="vertical"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
//create your views
</LinearLAyout>
</HorizontalScrollView>
关于android - horizontalScrollView 内部的布局,即屏幕大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4486795/