无法在 Android Studio 中看到完整的视图布局
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21565388/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unable to see completed view layout in Android Studio
提问by drew
I am creating a vertical LinearLayout that will be displayed in a vertical ScrollView. I can't find a way in Android Studio to see the portion of the LinearLayout that is below the bottom of the ScrollView. Is there any way to see the full layout rather than constraining it to the viewport provided by the renderer?
我正在创建一个垂直的 LinearLayout,它将显示在垂直的 ScrollView 中。我无法在 Android Studio 中找到查看 ScrollView 底部下方的 LinearLayout 部分的方法。有什么办法可以看到完整的布局而不是将其限制在渲染器提供的视口中?
回答by Brabbeldas
Like Drew said, creating a user defined device definition has been the only solution which worked for me. Below i show you the steps to follow:
就像 Drew 所说,创建用户定义的设备定义是唯一对我有用的解决方案。下面我向您展示要遵循的步骤:
Step 1) Within the preview-pane, open the Virtual Device Selectiondrop-down and select Add Device Definition..
步骤 1) 在预览窗格中,打开Virtual Device Selection下拉菜单并选择Add Device Definition..
Step 2) Within the Your Virtual Devicesdialog click the Create Virtual Devicebutton.
步骤 2) 在您的虚拟设备对话框中,单击创建虚拟设备按钮。
Step 3) Within the Select Hardwaredialog click the New Hardware Profilebutton.
步骤 3) 在“选择硬件”对话框中,单击“新建硬件配置文件”按钮。
Step 4) Within the Configure Hardware Profiledialog specify (f.e.) a Resolutionof 720 x 4000 px and a Screensizeof 12 inch. Also setting the Screensize results in a densityof xhdpi(thanks to Mete).
步骤 4) 在配置硬件配置文件对话框中指定 (fe)分辨率为 720 x 4000 像素和屏幕尺寸为 12 英寸。还设置分辨率汇总导致密度的xhdpi(感谢METE)。
Step 5) Close all dialogs and restart Android Studio.
Step 6) Open the Virtual Device Selectiondrop-down. The new user defined hardware profile can be found under Generic Phones and Tablets.
步骤 5) 关闭所有对话框并重新启动 Android Studio。步骤 6) 打开虚拟设备选择下拉菜单。可以在Generic Phones and Tablets下找到新的用户定义的硬件配置文件。
回答by drew
I've just discovered how. You need to create a user defined device definition in Android AVD - I created one that was 480 x 4000 pixels. Exit and restart Android Studio and then you can select this device in the preview renderer and can see 4000 pixels worth of LinearLayout.
我刚刚发现如何。您需要在 Android AVD 中创建一个用户定义的设备定义 - 我创建了一个 480 x 4000 像素的设备。退出并重新启动 Android Studio,然后您可以在预览渲染器中选择此设备,并可以看到 4000 像素的 LinearLayout。
回答by Tiago Pádua
Found a easier solution, in your layout
add something like below and adjust as you need:
找到了一个更简单的解决方案,在您layout
添加如下内容并根据需要进行调整:
android:layout_marginTop="-1500dp"
回答by Nabil Baadillah
回答by Eric JOYé
I hope the screenshot help you :
希望截图对你有帮助:
回答by davidgro
Android Studio will offer a toggleable full view, if the ScrollView is the root of the layout. I had put mine on top of the default RelativeLayout and had to manually fix that in the XML before the GUI would give me the full view.
如果 ScrollView 是布局的根,Android Studio 将提供可切换的完整视图。我已经将我的放在默认的 RelativeLayout 之上,并且必须在 GUI 为我提供完整视图之前在 XML 中手动修复它。
回答by Rakshit Tanti
You can use scrollY attribute to scroll the ScrollView in the preview. Using scrollY attribute with tools namespace will only scroll the view in the display and not in the actual app. And make sure you use px as the unit with scrollY attribute.
您可以使用 scrollY 属性在预览中滚动 ScrollView。将 scrollY 属性与 tools 命名空间一起使用只会在显示中滚动视图,而不会在实际应用中滚动。并确保使用 px 作为带有 scrollY 属性的单位。
tools:scrollY="150px"
回答by Momepukku
Update:Now you can scroll a ScrollView directly inside preview panel (I tested on Android studio version 2.3.2)
更新:现在您可以直接在预览面板内滚动 ScrollView(我在 Android Studio 2.3.2 版上测试过)
Short answer: Right click on your ScrollView and select Refactor > Extract > Layout.
简短回答:右键单击您的 ScrollView 并选择 Refactor > Extract > Layout。
Android-studio will extract your ScrollView into a new layout file and put tools:showIn="@layout/original_layout_file"
attribute at root layout(your ScrollView).
Android-studio 会将您的 ScrollView 提取到一个新的布局文件中,并将tools:showIn="@layout/original_layout_file"
属性放在根布局(您的 ScrollView)中。
Note: Android-studio will preview full layout if root layout is ScrollView.
注意:如果根布局是 ScrollView,Android-studio 将预览完整布局。
回答by seyedrezafar
回答by Eric JOYé
- click on the scrollView in conponent tree (on the right)
- click on the new button wich appears on the left (second row of toolbar)
- 单击组件树中的滚动视图(右侧)
- 单击左侧出现的新按钮(工具栏的第二行)