android - 如何将android导航抽屉添加到非空的主要活动?
问题描述
我有一个我一直在做的项目。它已经有很多代码,但我决定要为其添加一个导航抽屉。最好的方法是什么?我是否必须调整现有布局以适应导航抽屉?
这是我试图将导航抽屉添加到https://i.stack.imgur.com/wmDod.png的主片段
这些是 home 片段的 XML 代码:
?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView
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"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".fragments.HomeFragment">
<LinearLayout
android:id="@+id/home_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.denzcoskun.imageslider.ImageSlider
android:id="@+id/image_slider"
android:layout_width="match_parent"
android:layout_height="220dp"
app:iss_auto_cycle="true"
app:iss_delay="0"
app:iss_period="6000" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="9dp"
android:orientation="horizontal"
android:weightSum="2">
<TextView
android:id="@+id/Category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fontFamily="@font/andada"
android:text="Category"
android:textSize="21sp"
android:textStyle="bold" />
<TextView
android:id="@+id/category_see_all"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="8dp"
android:layout_weight="1"
android:fontFamily="@font/andada"
android:gravity="end"
android:text="See All"
android:textColor="@color/teal_700"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rec_category"
android:layout_width="wrap_content"
android:layout_height="160dp"
android:layout_marginLeft="9dp"
android:layout_marginTop="10dp" />
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_marginTop="10dp"
android:elevation="6dp"
app:cardCornerRadius="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/Recents"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="9dp"
android:fontFamily="@font/andada"
android:text="Recents "
android:textSize="21sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/Recents"
android:layout_marginLeft="9dp"
android:text="Recently added items for sale." />
<TextView
android:id="@+id/newProducts_see_all"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_marginRight="8dp"
android:fontFamily="@font/andada"
android:text="See All"
android:textColor="@color/teal_700"
android:textSize="18sp"
android:textStyle="bold" />
</RelativeLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/new_product_rec"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="7dp"
android:layout_marginTop="6dp"
android:padding="5dp" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/Popular_Items"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="9dp"
android:fontFamily="@font/andada"
android:text="Popular Items "
android:textSize="21sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/Popular_Items"
android:layout_marginLeft="9dp"
android:text="Most popular items posted." />
<TextView
android:id="@+id/popular_see_all"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_marginRight="8dp"
android:fontFamily="@font/andada"
android:text="See All"
android:textColor="@color/teal_700"
android:textSize="18sp"
android:textStyle="bold" />
</RelativeLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/popular_rec"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="7dp"
android:layout_marginTop="6dp"
android:padding="5dp" />
</LinearLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
这些是运行上面显示的主页片段的主要活动的代码:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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"
tools:context=".activities.MainActivity">
<FrameLayout
android:id="@+id/home_container"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
添加导航抽屉会弄乱我现有的代码吗?我需要帮助,谢谢!
解决方案
推荐阅读
- npm - gulp-sass 5 没有默认的 Sass 编译器;请自己设置一个
- git - 如何从在 Aws amplify 上运行的 git clone 继续
- node.js - 猫鼬 findOneAndUpdate 与 $push
- vue.js - 如何在 URL 参数 vue js 中包含动态内容
- service - Anti-corruption Layer 层在分层架构中的位置在哪里?集成第三方服务
- javascript - 如何在通过 JavaScript 或 jQuery 加载页面时删除 URL 中的某些单词
- r - 使用函数从不同级别的列表中提取数据
- javascript - node.js puppeteer evaluate() 返回 Unexpected 对象。每次抛出 TypeError
- javascript - 在 React 中使用 document.write 从外部脚本编写 HTML 内容
- android - DialogFragment 正在抛出 ClassCastException onAttach