我有一个包含多个TextEdits
的活动,在纵向模式下一切都显示完美。但当我将设备切换到横向模式时,一些视图没有被显示出来(它们被截断了)。我有什么办法可以在设备切换到横向模式时自动为视图添加滚动条呢?
你可以尝试这样做,这可能对你有所帮助:
在你的布局中添加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>
当屏幕空间不足以容纳所有项目时,将启用滚动条。然后您可以滚动屏幕。 因此,如果屏幕方向更改为横向,则可以滚动项目,在纵向上则完美显示一切,无法滚动。
ScrollView scroll = new ScrollView(yourContext);
scroll.setBackgroundColor(android.R.color.transparent);
scroll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
scroll.addView(yourView);