我在android中很初學。我試圖設計一個屏幕,在創建項目時我已經選擇了抽屜模板。因此,所需的基本功能就位,例如頂部的工具欄和左側的抽屜菜單圖標。現在我想在圖像視圖下方的工具欄和列表視圖中放置一個imageview。我正在使用下面的XML的佈局。Android工作室中的Android佈局問題
<?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.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<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" />
<ImageView
android:id="@+id/sliderTempImageView"
android:layout_width="match_parent"
android:layout_height="100dp"
android:scaleType="fitXY"
android:src="@drawable/slider_image1" />
</android.support.v4.widget.DrawerLayout>
</RelativeLayout>
但圖像覆蓋了工具欄和適合整個屏幕,即使我給了固定的高度100dp。一旦圖像視圖設置正確,我需要在imageview下面添加列表視圖。
添加的ImageView在'app_bar_main'。 –
嗨,我試過一樣,它的工作。但我想知道爲什麼它沒有像上面給出的代碼一樣工作。由於我是Android新手,如果我能夠知道原因,那會讓人更好地理解。 –
請參閱下面的答案。 –