我是android新手,一直在寻找解决方案,但到目前为止还没有运气.我想创建一个类似下图的布局.
我想有一个linearLayout,它是屏幕的大小.然后有另一个linearLayout,它也是屏幕的大小,但屏幕外.然后我可以在两个虚拟"屏幕"之间滚动.
有一篇有趣的文章解释了如何扩展scrollView类,以便我可以获得一个很酷的捕捉效果,所以如果我可以让它工作,我的应用程序将感觉很像在主屏幕之间滚动.
我已经阅读了有关权重以及scrollView的fillViewport ="true"的内容.我担心我不明白这些如何与horizontalScrollView一起使用以使linearLayouts填满屏幕.我尝试过fill_parent和wrap_content的各种组合,但无济于事.
正如我所看到的,只要构建子视图(每个"屏幕"中的元素)并考虑到屏幕可变性,此功能不会损害具有不同屏幕的设备之间的应用程序的可移植性.
这是我尝试的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>
Run Code Online (Sandbox Code Playgroud)
不幸的是,这甚至没有接近我正在寻找的东西.希望这可以做到......
感谢您的任何帮助或建议.
见这里解决方案是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>
Run Code Online (Sandbox Code Playgroud)
水平滚动视图可以无限地左右缩放,因此“填充父级”很可能不会像您在内部布局上期望的那样工作。您是否尝试过在内部布局上明确指定宽度?
就像是:
<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="400dp"
android:layout_height="fill_parent">
.....
</LinearLayout>
</HorizontalScrollView>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6520 次 |
| 最近记录: |