A ListView hidden behind a ToolBar and a button with a floating action hidden behind a ListView

My FAB will appear in the design window in the Android studio, but does not appear when I actually launch the application.

In addition, I have a ListView element that I specified should be located under the toolbar, but when I launch the application, it partially hides behind the toolbar.

<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">

<android.support.v7.widget.Toolbar
    android:id="@+id/my_toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />

<ListView
    android:id="@+id/android:list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_below="@+id/my_toolbar" />

<at.markushi.ui.CircleButton
    android:layout_width="64dp"
    android:layout_height="64dp"
    app:cb_color="@color/colorPrimary"
    app:cb_pressedRingWidth="8dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentEnd="true"
    android:layout_alignParentRight="true"
    android:onClick="openEditorForNewNote"
    android:src="@drawable/ic_action_add"/>

</RelativeLayout>

what the layout looks like in design mode

how the application appears at startup

What to do?

+4
source share
1 answer

My FAB will appear in the design window in the Android studio, but does not appear when I actually launch the application.

Try moving FAB over ListView in code like this:

<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">

<android.support.v7.widget.Toolbar
    android:id="@+id/my_toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />

<at.markushi.ui.CircleButton
    android:layout_width="64dp"
    android:layout_height="64dp"
    app:cb_color="@color/colorPrimary"
    app:cb_pressedRingWidth="8dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentEnd="true"
    android:layout_alignParentRight="true"
    android:onClick="openEditorForNewNote"
    android:src="@drawable/ic_action_add"/>

<ListView
    android:id="@+id/android:list"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_below="@+id/my_toolbar" />
</RelativeLayout>

, Android XML.

, ListView, , , , .

listView wrap_content ( , , ):

<ListView
    android:id="@+id/android:list"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_below="@+id/my_toolbar" />

ListView , ​​ match_parent, , .

+1

Source: https://habr.com/ru/post/1660997/


All Articles