我想在我activity.java文件中使用的工具栏和工具栏这样具有在其中只包含的ListView layout.xml文件。我怎么去呢?

问题描述 投票:1回答:1
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/categoriesLayout"
android:drawSelectorOnTop="true">

我尝试下面的XML。但我得到一个错误,指出“addView(查看,的LayoutParams)不支持的适配器视图”。

<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/categoriesLayout"
android:drawSelectorOnTop="true">

<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:elevation="4dp"
    android:theme="@style/ThemeOverlay.AppCompat.ActionBar"/>

</ListView>
android
1个回答
0
投票

你应该做这个:

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

    <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:elevation="4dp"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar" />

    <ListView
        android:id="@+id/categoriesLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:drawSelectorOnTop="true"
        android:orientation="vertical" />

</LinearLayout>

你得到这个错误,因为ListView的是不是一个ViewGroupViewGroupLinearLayout等 - 它不能像FrameLayout另一种观点认为内举行

© www.soinside.com 2019 - 2024. All rights reserved.