AdapterViewFlipper 前后视图内容混杂,宽高异常
我目前正在开发一个使用 AdapterViewFlipper 的 android 项目.动画正在运行,但问题是来自先前视图和当前视图的文本视图中的文本混合在一起,如图所示.
I am currently working on an android project that uses AdapterViewFlipper. The animation is working but the problem is that the texts in the textviews from previous and present views are intermixed as shown in the image.
此外,我一整天都在尝试将其宽度设为父级的一半,并将其高度设为容纳整个内容,但没有运气.我用谷歌搜索了很多,找不到任何具体的解决方案.
Also I have been trying the whole day to make its width half the parent and its height to accommodate the whole content but no luck. I have googled a lot and could not find any concrete solutions.
这里是AdapterViewFlipper的声明:
Here is the declaration of AdapterViewFlipper:
<AdapterViewFlipper
android:id="@+id/dataFlipper"
android:layout_above="@+id/btnReport"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dp"
android:clipChildren="false"
android:isScrollContainer="false"
android:background="@drawable/rounded_background"/>
这里是 AdapterViewFlipper 项的布局
and here is the layoutof AdapterViewFlipper item
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="2dp">
<TextView
android:id="@+id/txtEventName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge"
android:textAlignment="center"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/primary_dark_material_light"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="1.0">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_gravity="left"
android:layout_weight="0.5">
<TextView
android:id="@+id/txtTotalIncidents"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text=""/>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="@color/primary_dark_material_light"/>
<TextView
android:id="@+id/txtTotalInjured"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text=""/>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="@color/primary_dark_material_light"/>
<TextView
android:id="@+id/txtTotalFamily"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text=""/>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="@color/primary_dark_material_light"/>
<TextView
android:id="@+id/txtTotalComplete"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text=""/>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="@color/primary_dark_material_light"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="0.5">
<TextView
android:id="@+id/txtTotalDeath"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text=""/>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="@color/primary_dark_material_light"/>
<TextView
android:id="@+id/txtTotalMissing"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text=""/>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="@color/primary_dark_material_light"/>
<TextView
android:id="@+id/txtTotalEconomy"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text=""/>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="@color/primary_dark_material_light"/>
<TextView
android:id="@+id/txtTotalPartial"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text=""/>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="@color/primary_dark_material_light"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
对解决这些问题的任何帮助将不胜感激.提前致谢
Any help to resolve these problem would be appreciated. Thanks in advance
好的,我已经找到了解决我的问题的方法,但在这里忘了提及.如果有人面临同样的问题,解决方案是单行代码.事实上,这不是适配器的问题,而是片段的问题.只需在片段的 onCreateView
方法中添加以下代码行即可解决问题.
Ok I have already found solution to my problem but forgot to mention here. In case someone faces the same problem, the solution is a single line code. It was in fact not the problem with adapter but with the fragments. Just adding the following line of code in the onCreateView
method of the fragments solves the issue for me.
container.removeAllViews()