【发布时间】:2020-10-12 22:48:11
【问题描述】:
我正在创建一个垂直的 LinearLayout,它将显示在垂直的 ScrollView 中。我在 Android Studio 中找不到查看 ScrollView 底部下方的 LinearLayout 部分的方法。有什么办法可以查看完整的布局,而不是将其限制在渲染器提供的视口中?
【问题讨论】:
我正在创建一个垂直的 LinearLayout,它将显示在垂直的 ScrollView 中。我在 Android Studio 中找不到查看 ScrollView 底部下方的 LinearLayout 部分的方法。有什么办法可以查看完整的布局,而不是将其限制在渲染器提供的视口中?
【问题讨论】:
就像 Drew 所说,创建用户定义的设备定义是唯一对我有用的解决方案。下面我向您展示要遵循的步骤:
步骤 1) 在预览窗格中,打开 Virtual Device Selection 下拉菜单并选择 Add Device Definition..
步骤 2) 在您的虚拟设备对话框中点击创建虚拟设备按钮。
步骤 3) 在选择硬件对话框中点击New Hardware Profile按钮。
步骤 4) 在配置硬件配置文件对话框中指定(例如)720 x 4000 像素的分辨率和 12 英寸的屏幕尺寸。此外,设置屏幕尺寸会导致 xhdpi 的密度(感谢 Mete)。
步骤 5) 关闭所有对话框并重新启动 Android Studio。 步骤 6) 打开 虚拟设备选择 下拉菜单。可以在通用手机和平板电脑下找到新的用户定义硬件配置文件。
【讨论】:
我刚刚发现了方法。您需要在 Android AVD 中创建一个用户定义的设备定义——我创建了一个 480 x 4000 像素的设备。退出并重新启动Android Studio,然后您可以在预览渲染器中选择此设备,可以看到4000像素的LinearLayout。
【讨论】:
找到一个更简单的解决方案,在您的 layout 中添加如下内容并根据需要进行调整:
android:layout_marginTop="-1500dp"
【讨论】:
如果 ScrollView 是布局的根,Android Studio 将提供可切换的完整视图。我已经把我的放在默认的 RelativeLayout 之上,并且必须在 GUI 给我完整视图之前在 XML 中手动修复它。
【讨论】:
<include/>”中的技术,我们可以将布局中间的ScrollView提取到单独的XML文件中,并完整查看。
希望截图对你有所帮助:
【讨论】:
您可以使用 scrollY 属性在预览中滚动 ScrollView。使用带有 tools 命名空间的 scrollY 属性只会在显示中滚动视图,而不是在实际应用程序中滚动。并确保使用 px 作为具有 scrollY 属性的单位。
tools:scrollY="150px"
【讨论】:
更新:现在您可以直接在预览面板中滚动 ScrollView (我在 Android Studio 2.3.2 版本上测试过)
简答:右键单击 ScrollView 并选择 Refactor > Extract > Layout。
Android-studio 会将您的 ScrollView 提取到一个新的布局文件中,并将 tools:showIn="@layout/original_layout_file" 属性放在根布局(您的 ScrollView)中。
注意:如果根布局为 ScrollView,Android-studio 将预览完整布局。
【讨论】:
【讨论】:
另一个快速的替代解决方案是暂时隐藏顶部的布局,以便底部的布局可以显示在 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"。
我可能会迟到,但您只需将边距设置为负数以将滚动视图向左移动会容易得多。
例如:
边距:
左:-100px
现在您可以随心所欲地查看和编辑滚动视图!
【讨论】:
表格布局
<?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>
【讨论】:
我发现最好的方法是将设备设置为自定义。然后我们可以简单地通过拖动来改变布局。
【讨论】:
我的布局很长,即使使用垂直长分辨率也需要滚动布局,当我将布局编辑器设置为高分辨率时,屏幕无法完全流畅地滚动
通过将布局设置为 3.2_HVGA_slider_ADP1_API_27,屏幕滚动,我的问题解决了
【讨论】: