Why this textfield and appbar overlap?

58 views Asked by At

How can I resolve this problem? Here is the screen: image1

This is my xml fragment :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Utenti.Profilo.ProfiloFragment">


<TextView
    android:text="IL TUO PROFILO"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/textView3"
    android:textStyle="normal|bold"
    android:textSize="24sp"
    android:layout_weight="1"

    android:fontFamily="serif"
    android:lineSpacingExtra="10sp"
    android:textAllCaps="false"
    android:gravity="center_horizontal"
    android:layout_alignParentEnd="true"
    android:layout_alignParentStart="true" />

<TextView
    android:text="Le tue stanze:"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textView3"
    android:layout_alignParentStart="true"
    android:layout_marginStart="14dp"
    android:layout_marginTop="28dp"
    android:id="@+id/tue_stanze"
    android:textStyle="normal|italic"
    android:textSize="18sp" />

<ListView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/tue_stanze"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="19dp" />

I use a navigation drawer for first time and I need to create fragment to use for menu.

tnks for help.

EDIT: This is my content_main xml:

<?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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.bfco.bocci.androhouse.MainActivity"
tools:showIn="@layout/app_bar_main">

EDIT2: I use this "app_bar_main.xml" that include content_main:

<?xml version="1.0" encoding="utf-8"?>

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

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

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

<include layout="@layout/content_main" />

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="@dimen/fab_margin"
    android:src="@android:drawable/ic_dialog_email" />

And this is my main.xml :

<?xml version="1.0" encoding="utf-8"?>

<include
    layout="@layout/app_bar_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />


<FrameLayout
    android:id="@+id/frame_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
</FrameLayout>

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header_main"
    app:menu="@menu/activity_main_drawer" />

1

There are 1 answers

0
oddmeter On BEST ANSWER

It's a bit unclear as to exactly what container your fragment is contained in, but somewhere along the way, you should include this attribute

android:paddingTop="?attr/actionBarSize"

OR

android:layout_marginTop="?attr/actionBarSize"

in the appropriate container. Based on what I see above, you could simply add it to the root of your fragment posted above:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="?attr/actionBarSize"
    tools:context=".Utenti.Profilo.ProfiloFragment">

Ideally you'd handle it at a higher level, but this should suffice for your example.