在我的应用程序中,我在mainactivity中创建了一个列表视图,它打开了12个片段。我用fragmentTransaction.replace
打开它们。每个片段都有3个片段的滑动标签。其中一个我使用了两个滚动视图。我把屏幕分开左边和右边。像这样[scroll view | scroll view]
我在布局文件中编写了每个代码。(Java文件是空的,我不知道该写什么)。这里是滚动视图。(里面有20条)
<ScrollView
android:layout_width="0dp"
android:layout_height="match_parent"
android:isScrollContainer="false"
android:layout_weight="1">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="400dp"
android:layout_height="400dp"
android:src="@drawable/akrep_ahmet_kural"/>
<TextView
android:layout_width="210dp"
android:layout_height="wrap_content"
android:background="@color/burc_akrep"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Ahmet Kural"
android:textColor="@color/white"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"/>
<TextView
android:layout_width="210dp"
android:layout_height="wrap_content"
android:background="@color/burc_akrep"
android:text="10 Kasım 1982"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:textColor="@color/white" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="400dp"
android:layout_height="400dp"
android:src="@drawable/akrep_alp_kirsan" />
<TextView
android:layout_width="210dp"
android:layout_height="wrap_content"
android:background="@color/burc_akrep"
.
.
.
问题是当用户点击滚动视图选项卡时,它来的很慢,但滚动没有滞后。然后用户返回内存使用保持不变。然后用户打开另一个滚动视图选项卡,内存使用量再次增加,它变得像楼梯。之后,强制关闭。
那么该怎么办呢?
您应该使用Listview
或RecyclerView
,因为它不会在开始时加载所有视图,而是只加载可见的视图加上一个或两个视图,这将比您的方法节省资源。
看起来你应该使用ListView和适配器。
还请注意,"wrap_content"是相当无助于效率的改变宽度(例如,设置文本的TextView宽度设置为"wrap_content")可能会导致整个视图被重新绘制,减慢应用程序。