执行 api 请求时将布局显示为视图

问题描述 投票:0回答:2

我试图在执行 api 请求时显示视图布局,它是 xml 布局,并在请求完成后将其删除,布局包含 TextView 和动画,在布局显示后我需要将 TextView 设置为随机文本

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#091A24">

<com.airbnb.lottie.LottieAnimationView
    android:layout_width="match_parent"
    android:layout_height="250dp"
    android:layout_above="@+id/loading_splashscreenText"
    app:lottie_autoPlay="true"
    android:layout_marginBottom="15dp"
    android:id="@+id/lottiLoadingProgress"
    app:lottie_loop="true"/>


<TextView
    android:id="@+id/loading_splashscreenText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:layout_marginLeft="35dp"
    android:layout_marginRight="35dp"
    android:background="@color/black"
    android:fontFamily="@font/outfitsemibold"
    android:padding="5dp"
    android:text="Loading ... "
    android:textColor="@color/white"
    android:textSize="16dp" />
</RelativeLayout>

这是我的布局,我需要在布局显示后通过其 id 访问文本视图

android xml android-studio android-layout view
2个回答
0
投票

我实际上找到了解决方案,因为视图存根不会膨胀我使用对话框的整个布局,并将加载布局分配给对话框,如下所示

 dialog=new Dialog(context, R.style.AppTheme_FullScreenDialog);
    dialog.setContentView(R.layout.loading_screen);
    int width = ViewGroup.LayoutParams.MATCH_PARENT;
    int height = ViewGroup.LayoutParams.MATCH_PARENT;
    dialog.getWindow().setLayout(width,height);
    
    dialog.show();

执行请求后

dialog.dissmis();

0
投票

在调用 API 之前设置 llProgess 隐藏

private void callAPI() {
        llProgress.setVisibility(View.VISIBLE);
        Interface.callAPI("apiUrl/").enqueue(new Callback<FuelCityRoot>() {
            @Override
            public void onResponse(Call<FuelCityRoot> call, Response<FuelCityRoot> response) {
                llProgress.setVisibility(View.GONE);
            }

            @Override
            public void onFailure(Call<FuelCityRoot> call, Throwable t) {
                llProgress.setVisibility(View.GONE);
            }
        });
    }
© www.soinside.com 2019 - 2024. All rights reserved.