如何根据活动中的数据使整个活动可滚动 [英] How to make whole activity scrollable according to the data inside it

本文介绍了如何根据活动中的数据使整个活动可滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了LinearLayout,在其中放置了几个textview.对于每个视图,我完全使用权重.当数据长度过多而textview无法完全显示时,就会出现问题.我也尝试了tabletlayout,但由于最终tablelayout在具有权重的线性布局内,所以它不会起作用,因此它不会超出特定限制.我想知道如何在使用权重时显示所有数据来使活动滚动.

I have tried LinearLayout inside which I put several textview. I completely use weights for each and every view. Problem arises when data becomes too much in lenght and textview not shows it completely. I also tried tabletlayout but that thing also not works beacuse ultimately tablelayout is inside linear layout having weight,so it doesn't grows beyond a certain limit. I want to know how can I make a activity scrollable with showing all data while using weights.

推荐答案

在活动的xml布局中使用Scrollview.

Use Scrollview in xml Layout of your activity.

示例: 您的活动的XML代码:

Example: XML code for your activity:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:padding="10dp"
    android:fillViewport="false">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <ImageView
            android:id="@+id/imageView"
            android:layout_width="wrap_content"
            android:layout_height="200dp"
            android:scaleType="centerCrop"
            android:src="@drawable/image" />

        <Button
            android:id="@+id/button"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="KNOW MORE" />

        <TextView
            android:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/title"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/description"
            android:textAppearance="?android:attr/textAppearanceSmall" />
    </LinearLayout>
</ScrollView>

这篇关于如何根据活动中的数据使整个活动可滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆