0

У меня есть фрагмент с видом ресайклера и текстовое представление, которое будет отображаться, когда нет доступных данных. фрагмент размещается в деятельности, которая имеет компоновку координатора. Теперь проблема заключается в том, что текстовый вид не совсем в центре экрана, но когда панель инструментов сворачивается, она приходит в центр. Я хочу, чтобы текст был точно в центре. Как это сделать.Как разместить точки зрения точно в центре в плане координатора?

when tolbar is normal in [![when toolbar is collapsed состояние] 2] 2

Layout Activity в

<android.support.design.widget.CoordinatorLayout 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" 
    tools:context=".common.ui.BaseActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/AppTheme.AppBarOverlay" 
     app:elevation="0dp"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:layout_scrollFlags="scroll|enterAlways" 
      app:popupTheme="@style/AppTheme.PopupOverlay"> 
     </android.support.v7.widget.Toolbar> 


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

    <FrameLayout 
     android:id="@+id/home_container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 

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

<FrameLayout 
    android:id="@+id/navigation_view" 
    android:layout_width="280dp" 
    android:layout_height="match_parent" 
    android:layout_gravity="left" /> 

FRAGMENT==><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
<android.support.v7.widget.RecyclerView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/recycler_favourite"> 
</android.support.v7.widget.RecyclerView> 
    <TextView 
     android:id="@+id/empty_text_tv" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="14sp" 
     android:visibility="gone" 
     android:padding="@dimen/margin" 
     android:text="@string/empty_string_fav" 
     android:layout_centerInParent="true" /> 
    <ProgressBar 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:visibility="gone" 
     android:id="@+id/progress_bar"/> 
</RelativeLayout>` 
+0

размещение вашего макета xml поможет! –

+0

@LalitPoptani опубликовано PLS посмотреть. –

ответ

0

пытаются добавить это на TextView:

android:layout_centerVertical="true" 
android:layout_centerHorizontal="true" 

надеюсь, что это поможет.

0

Вот попробуйте следующее:

<FrameLayout 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"> 
<LinearLayout 
     android:id="@+id/llEmpty" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:gravity="center" 
     android:orientation="vertical"> 
<TextView 
     android:id="@+id/empty_text_tv" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="14sp" 
     android:visibility="gone" 
     android:padding="@dimen/margin" 
     android:text="@string/empty_string_fav" 
     android:gravity="center"/> 
    <ProgressBar 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:visibility="gone" 
     android:id="@+id/progress_bar"/> 
</LinearLayout> 
<android.support.v7.widget.RecyclerView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/recycler_favourite"> 
</android.support.v7.widget.RecyclerView> 


</FrameLayout> 
1

просто добавить к этому атрибуту ваш взгляд в:

android:layout_gravity="center" 
0

Try framelayout.

<FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:gravity="center"> 

     <ProgressBar 
      android:id="@+id/progressBar" 
      android:layout_width="40dp" 
      android:layout_height="40dp" 
      android:layout_gravity="center" /> 

     <TextView 
      android:id="@+id/empty" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:textColor="@color/black" /> 
</FrameLayout> 
0

Очень простая вещь, которую вы можете сделать, это просто добавить нижнее дополнение к вашему текстуру 'empty_text_tv'. В вашем случае вы можете установить его на attr/actionBarSize. По крайней мере, таким образом, текст будет центрирован, когда панель инструментов не будет свернута. Это выглядит намного лучше.

Если вам нужно, чтобы textview всегда был центрирован, вам нужно добавитьOnOffsetChangedListener в AppBarLayout. В этом методе 'onOffsetChanged' этого слушателя возьмите аргумент 'verticalOffset' и установите перевод textview в verticalOffset/2 (возможно, с некоторыми методами подписки на делегирование/событие).

Смежные вопросы