1

我有一个大约 3000 行的 xml 布局,用作问卷类型应用程序的布局。问卷的每一页都在不同的线性布局内,我使用View.GONE或设置代码中线性布局的可见性View.VISIBLE。通过这种方式,用户可以浏览页面而无需intents每次都加载新的。

但是,当我在应用程序中快速导航时(只需按下一个 button浏览屏幕),一些应该View.GONE显示的元素会出现并重叠在VISIBLE项目上。这只发生在其中包含列表视图的线性布局中。对于所有其他页面。

我可以快速滚动浏览它们,但是View.GONE当我导航太快时,有时会显示元素中具有列表视图的那些。我怎样才能解决这个问题 ?如果您想要代码,请告诉我...但是 xml 非常大。

TIA

编辑

这是我的 xml 代码的示例,我的 xml 中有 3000 行这样的重复...

  <LinearLayout
android:id="@+id/package_normal_samplesblood"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

    <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_marginBottom="70dp"
    android:orientation="vertical">

        <TextView
            android:id="@+id/textview_heading_b1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="23sp"
            android:layout_marginLeft="13dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="12dp"
            android:layout_marginBottom="12dp"
            android:textColor="#6f6f6f"
            android:layout_gravity="left"
            android:text="Blood Samples"/>

    <Button
    android:id="@+id/button_samples_blood"
    android:text="Add Blood Samples"
    android:layout_width="fill_parent"
    android:layout_height="65dp"
    android:textSize="20sp"
    android:layout_gravity="center"
    android:layout_marginTop="5dp"
    android:layout_marginBottom="5dp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"/>

    <ListView
    android:id="@+id/listview_samples_blood"
    android:scrollbarSize="0dp"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ffffff"
    android:orientation="vertical"
    /> 
        </LinearLayout>
       <RelativeLayout
android:orientation="horizontal"
android:background="#ffffff"
android:layout_width="fill_parent"
android:layout_height="75dp"
android:layout_marginTop="-75dp"

>
        <View
    android:layout_width="fill_parent"
    android:layout_alignParentTop="true"
    android:layout_height="1dp"
    android:background="#DEDEDE"
    android:layout_marginTop="2dp"/>
<ImageButton
            android:id="@+id/left9"
            android:background="@null"
            android:scaleType="fitEnd"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_marginTop="10dp"
            android:layout_marginLeft="10dp"
            android:layout_width="70px"
            android:layout_height="70px"
            android:src="@drawable/left"/>
<TextView
            android:id="@+id/textview_heading2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="25sp"
            android:layout_centerInParent="true"
            android:layout_marginTop="10dp"
            android:textColor="#6f6f6f"
            android:layout_gravity="center"
            android:text="RhODIS®"/>
<ImageButton
            android:id="@+id/right9"
            android:background="@null"
            android:scaleType="fitEnd"
            android:layout_centerVertical="true"
            android:layout_alignParentRight="true"
            android:layout_marginTop="10dp"
            android:layout_marginRight="10dp"
            android:layout_width="70px"
            android:layout_height="70px"
            android:src="@drawable/right"/>
 </RelativeLayout>
 </LinearLayout>


  <LinearLayout
android:id="@+id/package_normal_sampleshair"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

    <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_marginBottom="70dp"
    android:orientation="vertical">

        <TextView
            android:id="@+id/textview_heading_b2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="23sp"
            android:layout_marginLeft="13dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="12dp"
            android:layout_marginBottom="12dp"
            android:textColor="#6f6f6f"
            android:layout_gravity="left"
            android:text="Hair Samples"/>

    <Button
    android:id="@+id/button_samples_hair"
    android:text="Add Hair Samples"
    android:layout_width="fill_parent"
    android:layout_height="65dp"
    android:textSize="20sp"
    android:layout_gravity="center"
    android:layout_marginTop="5dp"
    android:layout_marginBottom="5dp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"/>

    <ListView
    android:id="@+id/listview_samples_hair"
    android:scrollbarSize="0dp"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ffffff"
    android:orientation="vertical"
    /> 
        </LinearLayout>
       <RelativeLayout
android:orientation="horizontal"
android:background="#ffffff"
android:layout_width="fill_parent"
android:layout_height="75dp"
android:layout_marginTop="-75dp"

>
        <View
    android:layout_width="fill_parent"
    android:layout_alignParentTop="true"
    android:layout_height="1dp"
    android:background="#DEDEDE"
    android:layout_marginTop="2dp"/>
<ImageButton
            android:id="@+id/left10"
            android:background="@null"
            android:scaleType="fitEnd"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_marginTop="10dp"
            android:layout_marginLeft="10dp"
            android:layout_width="70px"
            android:layout_height="70px"
            android:src="@drawable/left"/>
<TextView
            android:id="@+id/textview_heading2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="25sp"
            android:layout_centerInParent="true"
            android:layout_marginTop="10dp"
            android:textColor="#6f6f6f"
            android:layout_gravity="center"
            android:text="RhODIS®"/>
<ImageButton
            android:id="@+id/right10"
            android:background="@null"
            android:scaleType="fitEnd"
            android:layout_centerVertical="true"
            android:layout_alignParentRight="true"
            android:layout_marginTop="10dp"
            android:layout_marginRight="10dp"
            android:layout_width="70px"
            android:layout_height="70px"
            android:src="@drawable/right"/>
 </RelativeLayout>
 </LinearLayout>

然后这是我如何在代码中显示和隐藏线性布局的示例,这对 24 个左按钮和 24 个右按钮重复:

left24.setOnClickListener(new View.OnClickListener()
    {
        public void onClick(View v)
        {
            package_normal_welcomescreen.setVisibility(View.GONE);
            package_normal_package_details.setVisibility(View.GONE);
            package_normal_openbag.setVisibility(View.GONE);
            package_normal_kitnumber.setVisibility(View.GONE);
            package_normal_emptybag.setVisibility(View.GONE);
            package_normal_gpscoordinates.setVisibility(View.GONE);
            package_normal_image_scene.setVisibility(View.GONE);
            package_normal_samplesblood.setVisibility(View.GONE);
            package_normal_sampleshair.setVisibility(View.GONE);
            package_normal_samplestissue.setVisibility(View.GONE);
            package_normal_sampleshorn.setVisibility(View.GONE);
            package_normal_samplesother.setVisibility(View.GONE);
            package_normal_packsamples.setVisibility(View.GONE);
            package_normal_returnbag.setVisibility(View.GONE);
            package_normal_sealreturnbag.setVisibility(View.GONE);
            package_normal_image_sealedbag.setVisibility(View.GONE);
            package_normal_scanned.setVisibility(View.GONE);
            package_normal_animal_details.setVisibility(View.GONE);
            package_normal_animal_horn_details.setVisibility(View.GONE);
            package_normal_animal_ears.setVisibility(View.GONE);
            package_normal_area_details.setVisibility(View.GONE);

            package_normal_collecter_details.setVisibility(View.GONE);
            package_normal_additional_information.setVisibility(View.GONE);

             package_normal_owner_details.setVisibility(View.VISIBLE);
             package_normal_owner_details.bringToFront();
        }
    });

    right24.setOnClickListener(new View.OnClickListener()
    {
        public void onClick(View v)
        {
            if(Session.signatureIsCaptured)
            {
            package_normal_welcomescreen.setVisibility(View.GONE);
            package_normal_package_details.setVisibility(View.GONE);
            package_normal_openbag.setVisibility(View.GONE);
            package_normal_kitnumber.setVisibility(View.GONE);
            package_normal_emptybag.setVisibility(View.GONE);
            package_normal_gpscoordinates.setVisibility(View.GONE);
            package_normal_image_scene.setVisibility(View.GONE);
            package_normal_samplesblood.setVisibility(View.GONE);
            package_normal_sampleshair.setVisibility(View.GONE);
            package_normal_samplestissue.setVisibility(View.GONE);
            package_normal_sampleshorn.setVisibility(View.GONE);
            package_normal_samplesother.setVisibility(View.GONE);
            package_normal_packsamples.setVisibility(View.GONE);
            package_normal_returnbag.setVisibility(View.GONE);
            package_normal_sealreturnbag.setVisibility(View.GONE);
            package_normal_image_sealedbag.setVisibility(View.GONE);
            package_normal_scanned.setVisibility(View.GONE);
            package_normal_animal_details.setVisibility(View.GONE);
            package_normal_animal_horn_details.setVisibility(View.GONE);
            package_normal_animal_ears.setVisibility(View.GONE);
            package_normal_area_details.setVisibility(View.GONE);
            package_normal_owner_details.setVisibility(View.GONE);
            package_normal_collecter_details.setVisibility(View.GONE);
            package_normal_additional_information.setVisibility(View.VISIBLE);
            package_normal_additional_information.bringToFront();
            }
            else
            {
                Toast.makeText(Screen_Package_Normal.this, "Authorized Signature Required", Toast.LENGTH_LONG).show();
            }

        }

    });

我有不同类型的列表视图和适配器,内置自定义和android。我认为问题不在于适配器,因为它可以很好地显示列表视图,甚至在填充列表视图之前就出现问题......

4

1 回答 1

0

我有一个临时修复,不确定作为答案有多正确,但这解决了我的问题......我将它应用于我的整个布局,并在我隐藏和显示布局时添加动画,从而减慢它们的速度,从显示中删除重叠元素。

这是我添加到布局中的内容:

机器人:animateLayoutChanges="真"

于 2013-09-10T07:20:04.877 回答