简体   繁体   English

我如何在 Android Studio 的预览中看到长布局

[英]How i can see long layout in preview in Android Studio

I have a long Screen, and i set ScrollView, but in Preview screen in Android Studio i do not see part of the Screen.我有一个很长的屏幕,我设置了 ScrollView,但是在 Android Studio 的预览屏幕中,我看不到屏幕的一部分。 How i can see it?我怎么能看到在此处输入图片说明

I found another & pretty cool solution.我找到了另一个非常酷的解决方案。 It's not about size of the layout in preview.这与预览中的布局大小无关。 You can simulate scrolling instead, to see the hidden content.您可以改为模拟滚动,以查看隐藏的内容。

Use with tools, as it has influence only in preview.与工具一起使用,因为它仅在预览中有影响。 Then increase/decrease value for "scroll".然后增加/减少“滚动”的值。

<YourRootViewOfAnyType
xmlns:tools="http://schemas.android.com/tools"
...
tools:layout_marginTop="-200dp"
...
>

</YourRootViewOfAnyType>

Here's The Magic Solution :这是神奇的解决方案:

在此处输入图片说明

Click on the highlighted button to increase the size of the preview window.单击突出显示的按钮以增加预览窗口的大小。 Note : You can increase the size to any desired size!注意:您可以将大小增加到任何所需的大小!

在此处输入图片说明

Then use the zoom button to zoom and see the preview.然后使用缩放按钮进行缩放并查看预览。

在此处输入图片说明

Here's how it will look then.这就是它的样子。

在此处输入图片说明

To get the scroll Bar in application ....要在应用程序中获取滚动条.... 在此处输入图片说明

Use scroll view as the root view in your .xml file and then make the nesting of layouts.使用滚动视图作为 .xml 文件中的根视图,然后进行布局嵌套。

If you don't want the scrolling image to fade away in app then add the code under ScrollView :如果您不希望滚动图像在应用程序中消失,请在 ScrollView 下添加代码:

android:fadeScrollbars="false"

If you put your layouts in a ScrollView it should automatically (at least in Android Studio) show you everything.如果您将布局放在 ScrollView 中,它应该会自动(至少在 Android Studio 中)显示所有内容。

Another workaround is to make a new AVD with a big resolution, something like 4000px height, and use that for preview, worked for me :)另一种解决方法是制作一个具有大分辨率的新 AVD,例如 4000px 高度,并将其用于预览,对我有用:)

Open the xml of the layout.打开布局的xml。 In the preview pane press the 'Show Design + Blue print' button.在预览窗格中,按“显示设计 + 蓝图”按钮。 This will show the design along side the blue print.这将在蓝图旁边显示设计。 Hover the mouse over the blue print, you'll then be able to scroll.将鼠标悬停在蓝图上,然后您就可以滚动。 The design beside it will scroll simultaneously.它旁边的设计将同时滚动。

在此处输入图片说明

更新您的 android studio 现在您可以在滚动时看到预览。

As Verdan answered, you should use a ScrollView.正如 Verdan 回答的那样,您应该使用 ScrollView。
But the trick is that the ScrollView must be your root layout (at least temporary).但诀窍是 ScrollView 必须是您的根布局(至少是临时的)。
So just wrap all your layout into a ScrollView (even though you have another nested one or a ListView).因此,只需将所有布局包装到 ScrollView 中(即使您有另一个嵌套布局或 ListView)。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<!-- PUT All YOUR STUFF HERE -->

</ScrollView>

Then you will see all your layout in the preview.然后,您将在预览中看到所有布局。
And when your are done you can just remove it完成后,您可以将其删除

Open Android Studio Design View Click on the Blue Toggle Design or Blue Print Button Select Design + Blue Print打开 Android Studio 设计视图 单击蓝色切换设计或蓝色打印按钮选择设计 + 蓝色打印

Now hover on the blueprint view and when you scroll your design layout will also scroll automatically showing you the complete view.现在将鼠标悬停在蓝图视图上,当您滚动时,您的设计布局也会自动滚动显示完整的视图。 见示例

In Android Studio 4.1 you can easily increase height of preview by dragging the corresponding button:在 Android Studio 4.1您可以通过拖动相应按钮轻松增加预览高度:

展开预览尺寸按钮

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM