布局调用中的错误removeView()

时间:2014-01-24 15:50:59

标签: java android

我的片段有这个问题,这是剪切代码:

View mLoginFormView;
View mLoginStatusView;



@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {



    View rootView = inflater.inflate(R.layout.fragment_editor_css, container, true);

    mLoginFormView = rootView.findViewById(R.id.login_form);
    mLoginStatusView = rootView.findViewById(R.id.login_status);
   return rootView;

}


@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
private void showProgress(final boolean show) {
    // On Honeycomb MR2 we have the ViewPropertyAnimator APIs, which allow
    // for very easy animations. If available, use these APIs to fade-in
    // the progress spinner.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        int shortAnimTime = getResources().getInteger(
                android.R.integer.config_longAnimTime);



        mLoginStatusView.setVisibility(View.VISIBLE);
        mLoginStatusView.animate().setDuration(shortAnimTime)
                .alpha(show ? 1 : 0)
                .setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        mLoginStatusView.setVisibility(show ? View.VISIBLE
                                : View.GONE);
                    }
                });

        mLoginFormView.setVisibility(View.VISIBLE);
        mLoginFormView.animate().setDuration(shortAnimTime)
                .alpha(show ? 0 : 1)
                .setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        mLoginFormView.setVisibility(show ? View.GONE
                                : View.VISIBLE);
                    }
                });
    } else {
        // The ViewPropertyAnimator APIs are not available, so simply show
        // and hide the relevant UI components.
        mLoginStatusView.setVisibility(show ? View.VISIBLE : View.GONE);
        mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE);
    }
}

我的布局是:

    <merge xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context=".Home">


<LinearLayout
        android:id="@+id/login_status"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:gravity="center_horizontal"
        android:orientation="vertical"
        android:visibility="gone" >

        <ProgressBar
            style="?android:attr/progressBarStyleLarge"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp" />

        <TextView
            android:id="@+id/login_status_message"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="16dp"
            android:fontFamily="sans-serif-light"
            android:text="@string/login_progress_signing_in"
            android:textAppearance="?android:attr/textAppearanceMedium" />
    </LinearLayout>



<RelativeLayout 
    android:id="@+id/login_form"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    tools:context=".ValidationCss" >



    <TextView
        android:id="@+id/cssEditText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"

        android:layout_marginTop="44dp"
        android:ems="10"
        android:text="@string/urlString" />

</RelativeLayout>

</merge>

当我尝试跑步时,我遇到了这个问题:

java.lang.IllegalStateException:指定的子级已有父级。您必须首先在孩子的父母上调用removeView()。

0 个答案:

没有答案