代码之家  ›  专栏  ›  技术社区  ›  Prateek Raj

如何使我的布局能够向下滚动?

  •  73
  • Prateek Raj  · 技术社区  · 16 年前

    我无法向下滚动屏幕以查看“回复人:”部分中的数据。如何使布局可滚动?

    alt text

    4 回复  |  直到 9 年前
        1
  •  206
  •   Cristian    16 年前

    把这些都包在一个盒子里 ScrollView

    <?xml version="1.0" encoding="utf-8"?>
    <ScrollView
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent">
        <!-- Here you put the rest of your current view-->
    </ScrollView>
    

    正如大卫·赫德隆德所说, 只能包含一项。。。如果你有这样的经历:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent">
        <!-- bla bla bla-->
    </LinearLayout>
    

    必须将其更改为:

    <?xml version="1.0" encoding="utf-8"?>
    <ScrollView
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent">
        <LinearLayout
          android:layout_width="fill_parent"
          android:layout_height="fill_parent">
            <!-- bla bla bla-->
        </LinearLayout>
    </ScrollView>
    
        2
  •  41
  •   Vinil Narang    13 年前

    <ScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:fillViewport="true"> <!--IMPORTANT otherwise backgrnd img. will not fill the whole screen -->
    
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="@dimen/activity_vertical_margin"
            android:paddingLeft="@dimen/activity_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin"
            android:paddingTop="@dimen/activity_vertical_margin"
            android:background="@drawable/background_image"
        >
    
        <!-- Bla Bla Bla i.e. Your Textviews/Buttons etc. -->
        </RelativeLayout>
    </ScrollView>
    
        3
  •  4
  •   Sani Kamal    8 年前

    把这些都放在一个滚动视图里

    <?xml version="1.0" encoding="utf-8"?>
    
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="com.ruatech.sanikamal.justjava.MainActivity">
    <!-- Here you put the rest of your current view-->
    </ScrollView>
    
        4
  •  1
  •   Abhishek    6 年前

    是的,很简单。把你的代码放进去:

    <androidx.core.widget.NestedScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent" 
        android:layout_height="match_parent">
    
    //YOUR CODE
    
    </androidx.core.widget.NestedScrollView>
    
        5
  •  0
  •   VVN user7712621    10 年前

    设置 android:layout_height="250dp" xdp 哪里 x