如何根据其中的数据使整个活动可滚动 [英] 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屋!