【问题标题】:How to add scrolling to the view when screen orientation is changed to landscape? [closed]屏幕方向更改为横向时如何向视图添加滚动? [关闭]
【发布时间】:2013-03-31 14:14:36
【问题描述】:

我有一个带有多个TextEdits 的活动,并且在纵向模式下,一切都完美显示。但是当我将设备切换到横向模式时,几个视图没有显示(它们被剪切)。我可以以某种方式自动添加当设备切换到横向模式时滚动到视图?

【问题讨论】:

    标签: java android landscape


    【解决方案1】:

    检查您的设备何时处于纵向模式并添加:

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

    【讨论】:

    【解决方案2】:

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

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

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

    【讨论】:

    • android:fillViewport="true" 这很重要,为我工作 tanx @Volodymyr
    猜你喜欢
    • 1970-01-01
    • 2012-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多