【问题标题】:AdapterViewFlipper content of previous and present views intermix and abnormal width and heightAdapterViewFlipper 先前和当前视图的内容混合和异常的宽度和高度
【发布时间】:2015-11-08 14:18:07
【问题描述】:

我目前正在开发一个使用 AdapterViewFlipper 的 android 项目。动画正在运行,但问题是先前和当前视图的文本视图中的文本混合在一起,如图所示。

另外,我一整天都在尝试使其宽度为父级的一半,并使其高度适应整个内容,但没有运气。我用谷歌搜索了很多,找不到任何具体的解决方案。

这里是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项的布局

<?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>

任何解决这些问题的帮助将不胜感激。提前致谢

【问题讨论】:

    标签: android xml


    【解决方案1】:

    好的,我已经找到了我的问题的解决方案,但忘了在这里提及。如果有人遇到同样的问题,解决方案是单行代码。实际上,这不是适配器的问题,而是片段的问题。只需在片段的onCreateView 方法中添加以下代码行即可解决我的问题。

    container.removeAllViews()
    

    【讨论】:

      猜你喜欢
      • 2020-03-04
      • 2013-11-18
      • 2020-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-14
      • 2013-06-09
      • 1970-01-01
      相关资源
      最近更新 更多