2017-10-30 7 views
1

私はVISIBLEを作成しようとしているLinearLayoutを持っています。ただし、GONEを作成した後は、再び表示されません。メモとして、私はそれを不可視にすれば正常に動作します:問題なく現れて消えます。setVisibility(View.GONE)の後に表示が再現されない

これらの私のファイルは、以下のとおりです。

private void hideOrShowLoading(final boolean show) { 

    final ViewGroup spinnerWrapper = (ViewGroup)ll.findViewById(R.id.spinner_wrapper); 
    final View spinner = ll.findViewById(R.id.spinner); 

    if (show) { 
     spinnerWrapper.setVisibility(View.VISIBLE); // Not working after being set to GONE previously 
     final Animation rotation = AnimationUtils.loadAnimation(getContext(), R.anim.rotate); 
     rotation.setFillAfter(true); 
     spinner.startAnimation(rotation); 
    } else { 
     spinnerWrapper.setVisibility(View.GONE); 
     spinner.clearAnimation(); 
    } 
} 

任意のヒント:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <LinearLayout 
     android:id="@+id/noconnectionll" 
     android:visibility="gone" 
     android:padding="@dimen/node_default_spacing" 
     android:background="@color/category_no_internet" 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 
     <TextView 
      android:text="@string/no_internet_short" 
      android:textColor="#fff" 
      android:layout_weight="1" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content"/> 
     <Button 
      android:id="@+id/no_connection_retry" 
      android:text="@string/try_again" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"/> 
    </LinearLayout> 
    <ListView 
     android:dividerHeight="0dp" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" /> 
    <LinearLayout 
     android:id="@+id/spinner_wrapper" 
     tools:visibility="visible" 
     android:visibility="invisible" 
     android:background="#a0ffffff" 
     android:gravity="center_horizontal|center_vertical" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 
     <ImageView 
      android:id="@+id/spinner" 
      android:src="@drawable/ic_spinner" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 
     <TextView 
      android:id="@+id/category_loading" 
      android:text="@string/loading" 
      android:textColor="#000" 
      android:padding="@dimen/activity_padding" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 
    </LinearLayout> 
</LinearLayout> 

これは私が/非表示を表示するために使用している方法はありますか?高さ0、重さ1のListView上に何か関係がありますか?

おかげ

更新

また、私は運で、if (show)ブロックの後に次のことを試してみました:

listview.invalidate(); 
    spinnerWrapper.invalidate(); 
    ll.invalidate(); 
    ll.requestLayout(); 

llは両方が含まれているのLinearLayoutです。

+0

正常に動作しているようです。 'show'は正しく設定されていますか? – Cheticamp

+0

LinearLayout "spinner_wrapper" – Cyrus

+0

でvisibility = "visible"およびandroid:visibility = "invisible"の属性ツールを削除しようとしましたhideOrShowLoading()がUIスレッドで実行されていることを確認してください。 – rdbmsa

答えて

0

これはlayout_weight=1プロパティによって発生したと考えられますが、これを正しく修正できませんでした。

次のハックが機能しました。基本的には、spinnerWrapperを常に見える別の線形レイアウトで囲んでいます。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <LinearLayout 
     android:id="@+id/noconnectionll" 
     tools:visibility="visible" 
     android:visibility="gone" 
     android:padding="@dimen/node_default_spacing" 
     android:background="@color/category_no_internet" 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 
     <TextView 
      android:text="@string/no_internet_short" 
      android:textColor="#fff" 
      android:layout_weight="1" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content"/> 
     <Button 
      android:id="@+id/no_connection_retry" 
      android:text="@string/try_again" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"/> 
    </LinearLayout> 
    <ListView 
     tools:background="#d496d4" 
     android:dividerHeight="0dp" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" /> 
    <!-- Weird bug with layout_weight=1 on the listview above means we need this linearlayout --> 
    <LinearLayout 
     android:background="#0ca917" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 
     <LinearLayout 
      android:id="@+id/spinner_wrapper" 
      android:background="#a0ffffff" 
      android:gravity="center_horizontal|center_vertical" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 
      <ImageView 
       android:id="@+id/spinner" 
       android:src="@drawable/ic_spinner" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 
      <TextView 
       android:id="@+id/category_loading" 
       android:text="@string/loading" 
       android:textColor="#000" 
       android:padding="@dimen/activity_padding" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 
     </LinearLayout> 
    </LinearLayout> 
</LinearLayout> 
関連する問題