我在Youtube上从Slidenerd的视频中学习Android资料。学习在抽屉上制作Recycler View时遇到了问题。但是,Recycler View的位置不能成为图像视图的底部。我想在ImageView之后抛出那个像另一个Material Design应用程序。让我们看一下截图。
这是我的代码:
fragment_navigation_drawer.xml
<FrameLayout 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:background="#EEE"
tools:context="com.balinez.wdharmana.doahindu.NavigationDrawerFragment">
<LinearLayout
android:id="@+id/containerDrawerImage"
android:background="#F88C00"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- TODO: Update blank fragment layout -->
<ImageView
android:layout_width="280dp"
android:layout_height="140dp"
android:layout_marginBottom="18dp"
android:src="@drawable/bg_galungan"
/>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/drawer_list"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.RecyclerView>
</FrameLayout>
custom_row.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:padding="8dp"
android:id="@+id/listIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_bookmark1"
android:layout_gravity="center_vertical"
/>
<TextView
android:id="@+id/listText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Doa Sehari-hari"
android:layout_gravity="center_vertical"
/>
</LinearLayout>
activity_main.xml中
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<include android:id="@+id/app_bar"
layout="@layout/app_bar" style="@style/AppTheme.Base" />
<TextView
android:layout_below="@+id/app_bar"
android:text="@string/hello_world" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
<fragment
android:layout_width="@dimen/nav_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
android:id="@+id/fragment_navigation_drawer"
app:layout="@layout/fragment_navigation_drawer"
android:name="com.balinez.wdharmana.doahindu.NavigationDrawerFragment"
tools:layout="@layout/fragment_navigation_drawer" />
</android.support.v4.widget.DrawerLayout>
如果您也有同样的问题,请分享。谢谢你提前!
答案 0 :(得分:0)
如果没有必要将FrameLayout
用作您的父母,则可以像我使用的那样使用RelativeLayout
。
<?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"
android:background="#EEE"
tools:context="com.balinez.wdharmana.doahindu.NavigationDrawerFragment">
<LinearLayout
android:id="@+id/containerDrawerImage"
android:background="#F88C00"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<!-- TODO: Update blank fragment layout -->
<ImageView
android:layout_width="280dp"
android:layout_height="140dp"
android:layout_marginBottom="18dp"
android:src="@drawable/beach"
/>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/drawer_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/containerDrawerImage"
>
</android.support.v7.widget.RecyclerView>
</RelativeLayout>