1

У меня есть настраиваемая панель инструментов, и я хочу, чтобы мое представление было ниже панели инструментов. Но listview появляется на панели инструментов, а мой layout_below не работает. Я знаю, что многие вопросы задавали раньше. Но ничего не работает. Пожалуйста, помогите мнеLayout_below не работает в моем списке

ниже мой layoutxml

<?xml version="1.0" encoding="utf-8"?> 
<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="faisal.home.com.tafaqquhfiddin.DuwaListView"> 

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

<ListView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/MyListView" 
    android:layout_below="@+id/toolbar" 
    ></ListView> 

</RelativeLayout> 

toolbarlayout.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 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.Toolbar  
xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="?attr/actionBarSize" 
    android:background="@color/orange" 
    app:layout_scrollFlags="scroll|enterAlways" 
    app:titleTextColor="@color/white"></android.support.v7.widget.Toolbar> 

</LinearLayout> 
+0

Проблема в том, что ваша линейная компоновка на toolbarlayout.xml занимает всю высоту экрана, потому что вы определяете как спички родителя – HendraWD

ответ

2

Вопрос уже ответили другими пользователями ...

Я просто хотел бы добавить больше информации.

Ваш макет может быть намного проще. Вам не нужно использовать RelativeLayout. Просто используйте LinearLayout вместо android:orientation="vertical". Таким образом, вы будете иметь:

layout.xml

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    tools:context="faisal.home.com.tafaqquhfiddin.DuwaListView"> 

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

    <ListView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/MyListView" /> 

</LinearLayout> 

Панель инструментов Layout

<android.support.v7.widget.Toolbar 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="?attr/actionBarSize" 
    app:layout_scrollFlags="scroll|enterAlways" 
    android:background="@color/orange" 
    app:titleTextColor="@color/white" /> 
+0

вы можете мне помочь это [ссылка] (http://stackoverflow.com/questions/38687159/what-is-metadata-and-what-is-the-use-of-it-in-android) – FaisalAhmed

+0

@FaisalAhmed Done :) – W0rmH0le

+0

помогите мне еще раз http://stackoverflow.com/questions/38854909/can-fonts-and-its-size-can-be-changed-from-xml-in-android – FaisalAhmed

1

Снимите LinearLayout с вашего toolbarlayout.xml. Так что ваш toolbarlayout.xml должен выглядеть следующим образом:

<android.support.v7.widget.Toolbar  
xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="?attr/actionBarSize" 
    android:background="@color/orange" 
    app:layout_scrollFlags="scroll|enterAlways" 
    app:titleTextColor="@color/white"></android.support.v7.widget.Toolbar> 
0

Используйте ниже код, он будет работать.

мой layoutxml

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout 
    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:orientation="vertical" 
    tools:context="faisal.home.com.tafaqquhfiddin.DuwaListView"> 

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

    <ListView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/MyListView" 
     android:layout_below="@+id/toolbar" 
     ></ListView> 

</LinearLayout > 
0

Корневой макет высоты toolbarlayout.xml является "match_parent" изменить на "wrap_content". Используйте приведенный ниже код, который будет работать.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
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:orientation="vertical" 
tools:context="faisal.home.com.tafaqquhfiddin.DuwaListView"> 

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

<ListView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/MyListView" 
    android:layout_below="@+id/toolbar"/> 
</LinearLayout> 

toolbarlayout.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="match_parent" 
android:layout_height="wrap_content"> 

<android.support.v7.widget.Toolbar  
xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="?attr/actionBarSize" 
    android:background="@color/orange" 
    app:layout_scrollFlags="scroll|enterAlways" 
    app:titleTextColor="@color/white"/> 

</LinearLayout>