0

Ich habe eine RelativeLayout unten. Es gibt eine erweiterbare Ansicht und ein Layout für den Rahmen. RevealFrameLayout ist auf den unteren Bildschirmrand ausgerichtet und befindet sich unterhalb von ExpandableView. Wenn der Benutzer auf fab layer zeigt, beginnt die Animation vom Fab Center und zeigt das Layoutrahmen-Layout an.Falsche Ansichtsgröße in RelativeLayout

<?xml version="1.0" encoding="utf-8"?> 
<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:id="@+id/root" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

<FrameLayout 
    android:id="@+id/expandable_frame" 
    android:layout_width="match_parent" 
    android:layout_height="250dp" 
    android:layout_alignParentTop="true" 
    android:background="@color/colorPrimary" 
    android:elevation="16dp" 
    android:fitsSystemWindows="true" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

    <TextView 
     android:id="@+id/app_name_tv" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|start" 
     android:padding="16dp" 
     android:text="@string/app_name" 
     android:textAppearance="@style/ExtraLargeText"/> 

</FrameLayout> 

<TextView 
    android:id="@+id/error_tv" 
    android:layout_width="match_parent" 
    android:layout_height="60dp" 
    android:layout_below="@id/expandable_frame" 
    android:background="@color/mid_grey" 
    android:gravity="center" 
    android:textColor="@color/error_red" 
    android:visibility="invisible" 
    tools:text="@string/error_login" 
    tools:visibility="visible"/> 

<android.support.design.widget.TextInputLayout 
    android:id="@+id/username_til" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/error_tv" 
    android:layout_marginEnd="16dp" 
    android:layout_marginStart="16dp"> 

    <android.support.design.widget.TextInputEditText 
     android:id="@+id/username_tiet" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:hint="@string/username" 
     android:inputType="text" 
     android:lines="1" 
     android:nextFocusDown="@+id/password_tiet"/> 

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

<android.support.design.widget.TextInputLayout 
    android:id="@+id/password_til" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/username_til" 
    android:layout_marginEnd="16dp" 
    android:layout_marginStart="16dp"> 

    <android.support.design.widget.TextInputEditText 
     android:id="@id/password_tiet" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:hint="@string/password" 
     android:inputType="textPassword" 
     android:lines="1"/> 

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

<FrameLayout 
    android:id="@+id/loading_reveal_view" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_below="@id/expandable_frame" 
    android:background="@color/colorAccent" 
    android:visibility="invisible"> 

    <com.wang.avi.AVLoadingIndicatorView 
     android:id="@+id/loading_animation_view" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:visibility="invisible"/> 

</FrameLayout> 

<WebView 
    android:id="@+id/web_view" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_alignParentBottom="true" 
    android:layout_below="@id/expandable_frame" 
    android:visibility="gone"/> 

<android.support.design.widget.FloatingActionButton 
    android:id="@+id/login_fab" 
    android:layout_width="56dp" 
    android:layout_height="56dp" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentEnd="true" 
    android:layout_margin="16dp" 
    android:tint="@android:color/white" 
    app:srcCompat="@drawable/ic_ok"/> 

</RelativeLayout> 

I berechnen Zentrum von fab wie folgen aus:

 int cx = mLoginFab.getRight() - mLoginFab.getMeasuredWidth()/2; 
     int cy = mLoginFab.getBottom() - mLoginFab.getMeasuredHeight()/2; 

Aber ich bekomme Koordinaten, die immer niedriger als fab Standort sind. Es sieht so aus, als ob die Unterseite des Reveal Frame Layouts außerhalb der Grenzen des Telefonbildschirms liegt.

Weiß jemand, was mit diesem Layout falsch ist und wie man die Koordinaten des tatsächlichen Fertigungszentrums erhält?

Vielen Dank im Voraus.

Antwort

1

Versuchen getWidth() und getHeight statt getMeasuredWidth und getMeasuredHeight. Gemäß der documentation for View:

getMeasuredWidthAndState int()

Return die volle Breite Meßinformation für diese Ansicht, wie durch den letzten Anruf berechnet zu messen (int, int). Dieses Ergebnis ist eine Bitmaske, wie sie durch MEASURED_SIZE_MASK und MEASURED_STATE_TOO_SMALL definiert ist. Dies sollte nur bei Messungen und Layoutberechnungen verwendet werden. Verwenden Sie getWidth(), um zu sehen, wie weit eine Ansicht nach dem Layout ist.

Schwerpunkt ist mein, und dies gilt für getMeasuredWidth und getMeasuredHeight auch.