Android 对服务器的异步调用完成后隐藏视图
当我对服务器的请求等待响应时,我正在尝试显示一个预加载程序 但是当我试图用Android 对服务器的异步调用完成后隐藏视图,android,android-layout,visibility,android-ui,android-asynctask,Android,Android Layout,Visibility,Android Ui,Android Asynctask,当我对服务器的请求等待响应时,我正在尝试显示一个预加载程序 但是当我试图用setVisibility(View.GONE)隐藏预加载程序时它不会隐藏(即使其他内容确实可见) 当我运行一个函数,该函数假设移除预加载程序并直接显示其他内容(不在异步请求的回调中-它可以工作) 我的布局是这样的(我删除了所有不相关的东西,比如android:textproperties等): [请注意,我使用的加载程序是我创建的自定义视图(我不知道它是否与问题有关] <LinearLayout andro
setVisibility(View.GONE)隐藏预加载程序时代码>它不会隐藏(即使其他内容确实可见)
当我运行一个函数,该函数假设移除预加载程序并直接显示其他内容(不在异步请求的回调中-它可以工作)
我的布局是这样的(我删除了所有不相关的东西,比如android:text
properties等):
[请注意,我使用的加载程序是我创建的自定义视图(我不知道它是否与问题有关]
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/logo" />
<views.Loader
android:id="@+id/preloader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<LinearLayout
android:id="@+id/buttonsArea"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="@+id/my_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/my_dance"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/another_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
编辑:
更奇怪的是:
当我删除按钮reaa.setVisibility(View.VISIBLE);
行时,预加载程序确实隐藏了
非常感谢!!目前,我通过添加另一个LinearLayout
来包装加载程序,从而解决了这个问题,但在我看来,这是一种糟糕的实现方式
...
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_page);
init();
setLoading(true);
loadData();
}
private void init(){
preloader = (Loader) findViewById(R.id.preloader);
buttonsArea= (LinearLayout) findViewById(R.id.buttonsArea);
}
private void loadData(){
app.getManager().app_init(new OnAppInfoResponse(){
@Override
public void onResponse(boolean success) {
//this method runs on UI Thread through Handler
setLoading(false);
}
});
}
private void setLoading(boolean loading) {
this.loading = loading;
if(loading){
buttonsArea.setVisibility(View.GONE);
preloader.setVisibility(View.VISIBLE);
} else {
buttonsArea.setVisibility(View.VISIBLE);
preloader.setVisibility(View.GONE);
}
}