2017-02-01 15 views
0

我有一個圓圈,我只是一個在我的頁面中顯示它的一半,然後旋轉。我把它放在代碼和它的炒鍋裏,但是任何時候,我想要例如改變textviews的文本,或者在代碼中設置它的可見性,它會再次下降,如果我想再次推遲延遲顯示。 爲什麼它會發生,我該如何解決它? 或者如果你可以建議任何其他方式,我會很高興。當我更改我的佈局中的任何項目時,我已經以編程方式更改其度量的內部佈局,返回到其第一個度量

這是我的XML佈局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/background_blue" 
    android:fitsSystemWindows="true"> 



    <com.aa.ccc.activities.CustomLinearLayout 
     android:id="@+id/QuickPlayClipLayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_centerHorizontal="true" 
     android:gravity="center_horizontal"> 

     <RelativeLayout 
      android:id="@+id/clip_layout" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:gravity="center_horizontal" /> 
    </com.aa.ccc.activities.CustomLinearLayout> 

     <TextView 
      android:id="@+id/text_no_score" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentEnd="true" 
      /> 



</RelativeLayout> 

這是CustomLinearLayout類:

public CustomLinearLayout(Context context, AttributeSet attrs) { 
     super(context, attrs); 
     myContext = context; 
    } 

    @Override 
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) 
    { 
     super.onMeasure(widthMeasureSpec, heightMeasureSpec+((int)myContext.getResources().getDimension(R.dimen.quickplay_offset))); 
    } 

和我設置QuickPlayClipLayout的位置在我的代碼是這樣的:

@BindView(R.id.QuickPlayClipLayout) 
    LinearLayout mainLayout; 



    public static GameTestFragment newInstance() { 
     GameTestFragment fragment = new GameTestFragment(); 
     return fragment; 
    } 

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


    @Override 
    public void onAnimationStart(Animation animation) { 

    } 

    @Override 
    public void onAnimationEnd(Animation animation) { 
     mainLayout.setVisibility(View.VISIBLE); 
     mainLayout.layout(0, -(int) this.getResources().getDimension(R.dimen.quickplay_offset), 
       mainLayout.getWidth(), mainLayout.getHeight() + (int) this.getResources().getDimension(R.dimen.quickplay_offset)); 

    } 

    @Override 
    public void onAnimationRepeat(Animation animation) { 

    } 

回答

0

我發現解決我的問題。實際上,onmeaseure發生之後發生,這是延遲的原因。 我只是把CustomLinearLayout中的負邊距推到了一邊。並刪除執行該功能的代碼。

<com.aa.ccc.activities.CustomLinearLayout 
    android:id="@+id/QuickPlayClipLayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_alignParentTop="true" 
    android:layout_marginTop="-95dp" 
    android:gravity="center_horizontal|top"> 

    <RelativeLayout 
     android:id="@+id/clip_layout" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:gravity="center_horizontal" /> 
</com.aa.ccc.activities.CustomLinearLayout> 
相關問題