AVLoadingIndicatorView库在app中不可见

时间:2017-03-27 07:37:36

标签: android

添加了用于显示加载效果的库,但它不可见或看不到任何效果。虽然没有发生错误,但是在网络呼叫开始时没有看到效果。 show方法没有任何效果。目前我使用的是Android 4.1.2版。

XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="10">

    <RelativeLayout
        android:id="@+id/header"
        android:layout_width="match_parent"
        android:layout_height="50dp">

        <FrameLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent">

            <ImageView
                android:id="@+id/signin_back_button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_gravity="center"
                android:background="@drawable/ic_arrow_back_black_24dp"></ImageView>
        </FrameLayout>

        <TextView
            android:id="@+id/txt_signIn"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_alignParentRight="true"
            android:layout_gravity="right"
            android:background="@color/colorPrimary"
            android:gravity="center"
            android:padding="12dp"
            android:text="@string/sign_in"
            android:textColor="@color/white"
            android:textSize="18dp"></TextView>
    </RelativeLayout>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:gravity="center"
        android:text="Sign in to TruePay"
        android:textColor="@color/black"
        android:textSize="20dp"
        android:textStyle="bold"></TextView>

    <android.support.design.widget.TextInputLayout
        android:id="@+id/input_layout_email"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="50dp">

        <EditText
            android:id="@+id/signin_email_address"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:backgroundTint="@color/colorPrimary"
            android:hint="Username"
            android:inputType="textEmailAddress"></EditText>

    </android.support.design.widget.TextInputLayout>

    <android.support.design.widget.TextInputLayout
        android:id="@+id/input_layout_password"
        android:layout_width="match_parent"
        android:layout_marginLeft="20dp"
        android:layout_height="wrap_content">

        <EditText
            android:id="@+id/signin_password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginRight="20dp"
            android:hint="@string/signin_password"
            android:inputType="textPassword"></EditText>

    </android.support.design.widget.TextInputLayout>

    <TextView
        android:id="@+id/forgot_password"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="40dp"
        android:clickable="true"
        android:gravity="center"
        android:padding="10dp"
        android:text="@string/forgot_password"
        android:textColor="@color/black"
        android:textSize="18dp"
        android:textStyle="bold"></TextView>

    <TextView
        android:id="@+id/use_device_code"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="10dp"
        android:gravity="center"
        android:padding="10dp"
        android:text="@string/device_code"
        android:textColor="@color/black"
        android:textSize="18dp"
        android:textStyle="bold"></TextView>

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center">

        <com.wang.avi.AVLoadingIndicatorView
            android:id="@+id/avi"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:visibility="visible"
            app:indicatorName="BallPulseIndicator" />
    </RelativeLayout>

</LinearLayout>

java代码

public class SignIn extends BaseSupportFragment {
    private View view;
    private ImageView backPage;
    private TextView signInBtn;
    private TextView forgotPassword;
    private TextView deviiceCodes;
    TextInputLayout emailLayout,passwordLayout;
    EditText email,password;
    private static SessionManagement sessionManagement;
    AVLoadingIndicatorView avi;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.sign_in_fragment, container, false);
        initiateUI();
        setListener();
        return view;
    }

    public  void getTokenFromServer()
    {
        WeakHashMap<String, String> param = new WeakHashMap<>();
        param.put("username",email.getText().toString());
        param.put("password",password.getText().toString());
        Log.e("param...", String.valueOf(param));

        RetrofitInterface apiService = RetrofitClient.getClient().create(RetrofitInterface.class);
        Observable<TokenModel> call = apiService.postFishDetails(param)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread());
        call.subscribe(new Observer<TokenModel>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                //handle error
                Log.e("access",e.toString());
                try {
                    if (e instanceof HttpException) {
                        if (((HttpException) e).code() == 401) {
                            // GlobalBus.getBus().post(new TokenExpirationNotification("Token Expired"));
                        }
                    }
                    if (e instanceof IOException) {

                    }

                } catch (Exception e1) {

                }

            }

            @Override
            public void onNext(TokenModel response)
            {

                Constant.ACCESS_TOKEN = "Bearer" + response.getAccessToken();

                avi.hide();
                Intent intent = new Intent(getActivity(), DrawerAct.class);
                getActivity().startActivity(intent);
                getActivity().finish();


            }

        });

    }
    private void requestFocus(View view) {
        if (view.requestFocus()) {
            getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
        }
    }


    private void setListener() {
        backPage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getActivity().getSupportFragmentManager().popBackStack();
            }
        });
        signInBtn.setOnClickListener(new View.OnClickListener()
        {

            @Override
            public void onClick(View v)
            {
                if(TextUtils.isEmpty(email.getText().toString()))
                {
                    emailLayout.setError("Enter Username");
                    requestFocus(email);
                }
                else if(TextUtils.isEmpty(password.getText().toString()))
                {
                    passwordLayout.setError("Enter Password");
                    requestFocus(password);
                }
                else
                {

                    avi.show();
                    getTokenFromServer();
                }

            }
        });

        forgotPassword.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                replaceFragment(R.id.frame_layout, new ForgotPassword());
            }
        });

        deviiceCodes.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                replaceFragment(R.id.frame_layout, new DeviceCode());
            }
        });
    }

    private void initiateUI()
    {

        backPage = (ImageView) view.findViewById(R.id.signin_back_button);
        signInBtn = (TextView) view.findViewById(R.id.txt_signIn);
        forgotPassword = (TextView) view.findViewById(R.id.forgot_password);
        deviiceCodes = (TextView) view.findViewById(R.id.use_device_code);

        emailLayout=(TextInputLayout)view.findViewById(R.id.input_layout_email);
        passwordLayout=(TextInputLayout)view.findViewById(R.id.input_layout_password);

        email=(EditText)view.findViewById(R.id.signin_email_address);
        password=(EditText)view.findViewById(R.id.signin_password);

        avi=(AVLoadingIndicatorView)view.findViewById(R.id.avi);

    }

}

2 个答案:

答案 0 :(得分:2)

解决了这个问题。忘了提到默认的白色的indiacator颜色,所以装载机实际上工作但是看不见;

XML代码

<com.wang.avi.AVLoadingIndicatorView
        android:id="@+id/avi"
        style="@style/AVLoadingIndicatorView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:visibility="gone"
        app:indicatorColor="@color/colorPrimaryDark"
        app:indicatorName="LineSpinFadeLoaderIndicator" />

答案 1 :(得分:0)

您的父级布局为LinearLayout,请尝试使用RelativeLayout包装主布局,并将AVLoadingIndicatorView放在LinearLayout

之外