【问题标题】:Unable to see completed view layout in Android Studio在 Android Studio 中看不到完整的视图布局
【发布时间】:2020-10-12 22:48:11
【问题描述】:

我正在创建一个垂直的 LinearLayout,它将显示在垂直的 ScrollView 中。我在 Android Studio 中找不到查看 ScrollView 底部下方的 LinearLayout 部分的方法。有什么办法可以查看完整的布局,而不是将其限制在渲染器提供的视口中?

【问题讨论】:

    标签: android android-studio


    【解决方案1】:

    就像 Drew 所说,创建用户定义的设备定义是唯一对我有用的解决方案。下面我向您展示要遵循的步骤:

    步骤 1) 在预览窗格中,打开 Virtual Device Selection 下拉菜单并选择 Add Device Definition..

    步骤 2) 在您的虚拟设备对话框中点击创建虚拟设备按钮。

    步骤 3) 在选择硬件对话框中点击New Hardware Profile按钮。

    步骤 4) 在配置硬件配置文件对话框中指定(例如)720 x 4000 像素的分辨率和 12 英寸的屏幕尺寸。此外,设置屏幕尺寸会导致 xhdpi密度(感谢 Mete)。

    步骤 5) 关闭所有对话框并重新启动 Android Studio。 步骤 6) 打开 虚拟设备选择 下拉菜单。可以在通用手机和平板电脑下找到新的用户定义硬件配置文件。

    【讨论】:

    • 感谢您对所有图片和有用描述的回答
    • 看不到任何增加高度的地方
    【解决方案2】:

    我刚刚发现了方法。您需要在 Android AVD 中创建一个用户定义的设备定义——我创建了一个 480 x 4000 像素的设备。退出并重新启动Android Studio,然后您可以在预览渲染器中选择此设备,可以看到4000像素的LinearLayout。

    【讨论】:

    • +1,因为我没有拆开我的观点并说明需要重新启动。
    • 这是迄今为止我找到的唯一合适的解决方案。有一个问题; Android Studio 在使用此分辨率时,会自动将密度设置为 xxxhdpi。有没有办法将密度设置回hdpi?我正在使用 Android Studio v1.2
    • @Brabbeldas 创建配置文件时,您可以以像素为单位提供宽度和高度,但您也可以以英寸为单位提供“屏幕大小”,这些设置的组合设置密度。例如,我将我的设置为 480x4000,屏幕尺寸为 16 英寸,这给了我 hdpi
    • 我添加了一个新答案,其中包含描述如何创建用户定义的设备定义的屏幕截图。 @Drew,如果你觉得它对其他人有用,你可以接受它作为正确答案。
    • 太棒了!对我来说,调整大小一次没有用!下面的回答 stackoverflow.com/a/31582758/1752988 也很有帮助!
    【解决方案3】:

    找到一个更简单的解决方案,在您的 layout 中添加如下内容并根据需要进行调整:

    android:layout_marginTop="-1500dp"
    

    【讨论】:

    • 最佳答案,但最好使用:tools:layout_marginTop="-1500dp"。这样负滚动只适用于布局编辑器,而不适用于运行时。
    • 当@Eric 提到的按钮不可用时很有用。
    【解决方案4】:

    在新版本的 android studio 中(我不知道是哪个版本,但我现在使用的是最新的 2.3.3)你可以通过拖动来调整预览布局的大小

    【讨论】:

    • +1 对我有用,但必须手动将上述 gif 中的设备从 nexus 4 更改为“自定义”才能显示拖动按钮。
    【解决方案5】:

    如果 ScrollView 是布局的根,Android Studio 将提供可切换的完整视图。我已经把我的放在默认的 RelativeLayout 之上,并且必须在 GUI 给我完整视图之前在 XML 中手动修复它。

    【讨论】:

    • 你是怎么找到这个的?
    • @MattSzaro 我不记得我在哪里找到的信息,但如果你的意思是在哪里可以找到 XML 来更改它,所以滚动视图是根项目,当你打开 .xml 以查看视图:“设计”和“文本”。单击“文本”。如果您的意思是在进行更改后在哪里可以找到切换,我认为您需要关闭并重新打开项目一次(也许)然后在“设计”中它是工具栏第二行中最左边的按钮,带有一个图标看起来是三列纸之类的:“切换视口渲染模式”。
    • @davidgro,我正在寻找工具栏中的选项。谢谢!这真的很有帮助。
    • 结合“Re-using Layouts with <include/>”中的技术,我们可以将布局中间的ScrollView提取到单独的XML文件中,并完整查看。
    • 如果你的滚动视图不是根视图怎么办。希望他们能扩展整个该死的东西,只需将手机屏幕的轮廓放在顶部以显示可视区域。
    【解决方案6】:

    希望截图对你有所帮助:

    【讨论】:

    • 当我单击组件树上的滚动视图时缺少此按钮
    • 刚刚发现scrollview必须在顶层才能显示按钮。谢谢埃里克!
    • 完整视图选项解决了我的垂直滚动视图问题,但是我有一个嵌入的水平滚动视图,它仍然只有部分可见,(其余部分延伸到右侧)有没有办法在不使用自定义设备选项的情况下解决此问题?
    • 这是完美的答案。它比非常高的设备配置文件要好。并且在 android studio 0.1.7+ 中可用
    【解决方案7】:

    您可以使用 scrollY 属性在预览中滚动 ScrollView。使用带有 tools 命名空间的 scrollY 属性只会在显示中滚动视图,而不是在实际应用程序中滚动。并确保使用 px 作为具有 scrollY 属性的单位。

    tools:scrollY="150px"
    

    【讨论】:

      【解决方案8】:

      更新:现在您可以直接在预览面板中滚动 ScrollView (我在 Android Studio 2.3.2 版本上测试过)

      简答:右键单击 ScrollView 并选择 Refactor > Extract > Layout

      Android-studio 会将您的 ScrollView 提取到一个新的布局文件中,并将 tools:showIn="@layout/original_layout_file" 属性放在根布局(您的 ScrollView)中。

      注意:如果根布局为 ScrollView,Android-studio 将预览完整布局。

      【讨论】:

      • @Tequilaman 如果您使用的是 Android Studio 2.3.2 版,您可以在预览面板上使用鼠标滚轮滚动 ScrollView 的内容
      【解决方案9】:

      在 Android Studio 版本 3.2.1 中,您可以在预览面板上选择“自定义”设备,然后将预览大小调整到您需要的任何高度。

      【讨论】:

      • 这是最简单的方法!最好的。
      【解决方案10】:
      • 点击组件树中的scrollView(右侧)
      • 点击左侧出现的新按钮(工具栏的第二行)

      【讨论】:

      • 您可以添加截图吗?我看不到任何新按钮出现。
      • @Brabbeldas 新按钮名为“切换视口渲染模式”。也许可以帮助您stackoverflow.com/a/30443662/1323374
      【解决方案11】:

      另一个快速的替代解决方案是暂时隐藏顶部的布局,以便底部的布局可以显示在 Android Studio 的可见窗口中。

      android:visibility="gone" 放在要隐藏的布局上。

      例子:

      <HorizontalScrollView
                  android:visibility="gone"
                  android:id="@+id/hsv02"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_alignStart="@+id/ll24"
                  android:layout_below="@+id/ll199">
      
       </HorizontalScrollView>
      

      【讨论】:

      • 这是一个非常不舒服的解决方案......至少不要这样做是非常必要的。
      • 使用tools:visibility="gone"
      【解决方案12】:

      我可能会迟到,但您只需将边距设置为负数以将滚动视图向左移动会容易得多。

      例如:

      边距:

      左:-100px

      现在您可以随心所欲地查看和编辑滚动视图!

      【讨论】:

        【解决方案13】:

        表格布局

        <?xml version="1.0" encoding="utf-8"?>
        <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:stretchColumns="1">
            <TableRow android:padding="5dip">
                <TextView
                    android:layout_height="wrap_content"
                    android:text="New Product Form"
                    android:typeface="serif"
                    android:layout_span="2"
                    android:gravity="center_horizontal"
                    android:textSize="20dip" />
            </TableRow>
            <TableRow>
                <TextView
                    android:layout_height="wrap_content"
                    android:text="Product Code:"
                    android:layout_column="0"/>
                <EditText
                    android:id="@+id/prod_code"
                    android:layout_height="wrap_content"
                    android:layout_column="1"/>
            </TableRow>
            <TableRow>
                <TextView
                    android:layout_height="wrap_content"
                    android:text="Product Name:"
                    android:layout_column="0"/>
                <EditText
                    android:id="@+id/prod_name"
                    android:layout_height="wrap_content"
                    android:scrollHorizontally="true" />
            </TableRow>
            <TableRow>
                <TextView
                    android:layout_height="wrap_content"
                    android:text="Product Price:" />
                <EditText
                    android:id="@+id/prod_price"
                    android:layout_height="wrap_content" />
            </TableRow>
            <TableRow>
                <Button
                    android:id="@+id/add_button"
                    android:text="Add Product"
                    android:layout_height="wrap_content" />
                <Button
                    android:id="@+id/cancel_button"
                    android:text="Cancel"
                    android:layout_height="wrap_content" />
            </TableRow>
        </TableLayout>
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        GridLAYOUT
        
        <?xml version="1.0" encoding="utf-8"?>
        <GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:id="@+id/GridLayout1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:columnCount="3"
            android:rowCount="2"
            tools:context=".Main3Activity" >
            <Button
                android:id="@+id/button3"
                android:layout_column="0"
                android:layout_gravity="fill_horizontal"
                android:layout_row="0"
                android:text="Button"
                />
            <Button
                android:id="@+id/button1"
                android:layout_column="1"
                android:layout_gravity="fill_horizontal"
                android:layout_row="0"
                android:text="Button" />
            <Button
                android:id="@+id/button2"
                android:layout_column="2"
                android:layout_gravity="fill_vertical"
                android:layout_row="0"
                android:layout_rowSpan="2"
                android:text="Button" />
            <Button
                android:id="@+id/button4"
                android:layout_column="0"
                android:layout_columnSpan="2"
                android:layout_gravity="fill_horizontal"
                android:layout_row="1"
                android:text="Button" />
        </GridLayout>
        
        
        
        
        
        ANOTHER TABLE LAYOUT
        
        <?xml version="1.0" encoding="utf-8"?>
        <android.widget.TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:stretchColumns="1"
            tools:context="com.example.dhanya.uitablelayout.MainActivity">
            <TableRow
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">
                <TextView
                    android:text="Time"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_column="0" />
                <TextClock
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/textClock"
                    android:layout_column="1" />
            </TableRow>
            <TableRow>
                <TextView
                    android:text="First Name"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_column="0" />
                <EditText
                    android:width="200px"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />
            </TableRow>
            <TableRow>
                <TextView
                    android:text="Last Name"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_column="0" />
                <EditText
                    android:width="100px"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />
            </TableRow>
            <TableRow
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">
                <RatingBar
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_span="2"
                    android:id="@+id/ratingBar"
                    android:layout_column="0" />
            </TableRow>
            <TableRow
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"/>
            <TableRow
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">
                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Submit"
                    android:layout_span="2"
                    android:id="@+id/button"
                    android:layout_column="0" />
            </TableRow>
        </android.widget.TableLayout>
        

        【讨论】:

          【解决方案14】:

          我发现最好的方法是将设备设置为自定义。然后我们可以简单地通过拖动来改变布局。

          【讨论】:

            【解决方案15】:

            我的布局很长,即使使用垂直长分辨率也需要滚动布局,当我将布局编辑器设置为高分辨率时,屏幕无法完全流畅地滚动

            通过将布局设置为 3.2_HVGA_slider_ADP1_API_27,屏幕滚动,我的问题解决了

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2019-01-03
              • 2023-03-12
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多