Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/382.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/225.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 当屏幕方向更改为横向时,如何向视图添加滚动?_Java_Android_Landscape - Fatal编程技术网

Java 当屏幕方向更改为横向时,如何向视图添加滚动?

Java 当屏幕方向更改为横向时,如何向视图添加滚动?,java,android,landscape,Java,Android,Landscape,我有一个包含多个文本编辑的活动,在纵向模式下,所有内容都能完美显示。但当我将设备切换到横向模式时,多个视图没有显示(它们被剪切)。当设备切换到横向模式时,我能否以某种方式自动将滚动添加到视图中?检查设备处于纵向模式时,并添加: ScrollView scroll = new ScrollView(yourContext); scroll.setBackgroundColor(android.R.color.transparent); scroll.setLayoutParams(new Layo

我有一个包含多个
文本编辑的活动,在纵向模式下,所有内容都能完美显示。但当我将设备切换到横向模式时,多个视图没有显示(它们被剪切)。当设备切换到横向模式时,我能否以某种方式自动将滚动添加到视图中?

检查设备处于纵向模式时,并添加:

ScrollView scroll = new ScrollView(yourContext);
scroll.setBackgroundColor(android.R.color.transparent);
scroll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
scroll.addView(yourView);

您可以尝试这样做,这可能对您有所帮助:

将ScrollView添加到布局并设置此标志
android:fillViewport=“true”
例如:

 <ScrollView
    android:id="@+id/scrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        // your layout

    </LinearLayout>
</ScrollView>

//你的布局
当屏幕上没有足够的空间放置项目时,将启用滚动。然后你可以滚动屏幕。
因此,如果屏幕方向更改为横向,您可以滚动项目,并且在纵向中,所有内容都可以完美显示,而无需滚动。

您应该查看文档:使用getResources().getConfiguration().orientation获取当前方向AndRoid:fillViewport=“true”这非常重要,为我工作tanx@Volodymyr