【问题标题】:Resizable layout (by pulling)可调整大小的布局(通过拉动)
【发布时间】:2023-02-26 06:08:45
【问题描述】:

我有我的布局,直到现在它工作正常,但我想通过上下拉动 <ScrollView android:id="@+id/to_Resize" 来调整大小。可能我必须添加一些视图,但从这一点上我不知道哪个以及如何配置它。有人有主意吗? 我的 xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:id="@+id/main"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <LinearLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"></LinearLayout>

    <ScrollView
        android:id="@+id/to_Resize"
        android:layout_width="match_parent"
        android:layout_height="250dp">

        <LinearLayout
            android:id="@+id/text_block"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:isScrollContainer="true"
            android:orientation="vertical" />
    </ScrollView>

    <TextView
        android:id="@+id/PathShow"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="TextView" />

    <ScrollView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#FFFFFF">

        <GridLayout
            android:id="@+id/pew1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:columnCount="4"
            android:rowCount="12">

        </GridLayout>
    </ScrollView>

</LinearLayout>

【问题讨论】:

    标签: java android layout


    【解决方案1】:

    为了使滚动视图可调整大小,你可以把它包在一个嵌套滚动视图而不是 LinearLayout。

    为什么是嵌套滚动视图?

    A:NestedScrollView 是 ScrollView 的子类,允许您在另一个可滚动视图中有一个可滚动视图。

    这是您的布局 XML 的更新版本,其中 ScrollView 包裹在 NestedScrollView 中

    <?xml version="1.0" encoding="utf-8"?>
    <androidx.core.widget.NestedScrollView
        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:id="@+id/main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        tools:context=".MainActivity">
    
        <LinearLayout
            android:id="@+id/container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal"></LinearLayout>
    
        <ScrollView
            android:id="@+id/to_Resize"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
    
            <LinearLayout
                android:id="@+id/text_block"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:isScrollContainer="true"
                android:orientation="vertical" />
        </ScrollView>
    
        <TextView
            android:id="@+id/PathShow"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="TextView" />
    
        <ScrollView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="#FFFFFF">
    
            <GridLayout
                android:id="@+id/pew1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:columnCount="4"
                android:rowCount="12">
    
            </GridLayout>
        </ScrollView>
    
    </androidx.core.widget.NestedScrollView>

    通过此更改,您应该能够通过上下拉动 ScrollView 来调整它的大小。

    【讨论】:

      猜你喜欢
      • 2021-07-02
      • 2012-10-11
      • 2012-07-12
      • 1970-01-01
      • 2011-11-20
      • 2013-10-09
      • 1970-01-01
      • 2014-04-29
      • 1970-01-01
      相关资源
      最近更新 更多