- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我的 MainActivity.java 类
package com.example.bottomnavigationdrawer;
import androidx.appcompat.app.AppCompatActivity;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.NavigationUI;
import androidx.viewpager.widget.ViewPager;
import android.os.Bundle;
import com.google.android.material.bottomnavigation.BottomNavigationView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
BottomNavigationView bottomNavigationView=findViewById(R.id.bottomNavigationView);
NavController navController= Navigation.findNavController(this,R.id.nav_host_fragment);
NavigationUI.setupWithNavController(bottomNavigationView,navController);
}
}
这是我的activity_main.xml:
<?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=".MainActivity">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottomNavigationView"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:itemTextColor="#00FAF7F7"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="@menu/bottom_nav_menu" />
<fragment
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="0dp"
android:layout_height="0dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="@+id/bottomNavigationView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="@navigation/nav_graph" />
</androidx.constraintlayout.widget.ConstraintLayout>
这是我的 HomeFragment.java 类:
package com.example.bottomnavigationdrawer;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.smarteist.autoimageslider.SliderView;
/**
* A simple {@link Fragment} subclass.
*/
public class HomeFragment extends Fragment {
public HomeFragment() {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_home, container, false);
SliderView imageView = (SliderView) view.findViewById(R.id.imageSlider);
return view;
}}
这是我的fragment_home.xml:
<?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="fill_parent"
android:layout_height="fill_parent"
android:paddingBottom="3dp"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:paddingTop="3dp"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".HomeFragment">
<!-- TODO: Update blank fragment layout -->
<TextView
android:gravity="center"
android:textSize="70sp"
android:textColor="#FAF8F8"
android:background="#25212E"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Home" />
</RelativeLayout>
我是 Android 新手,我已经搜索了很多相关内容。但我得到的每个教程都是通过主要 Activity 、模型、适配器来实现的。但我必须在主要 Activity 的主 fragment 上执行此操作。
最佳答案
其实我不太明白你的问题。如果您想了解 recyclerview 和卡片 View 以及底部导航 View ,请按照本教程操作:
这很容易。如果你想设置水平滚动使用 LinearLayoutManager 像这样
LinearLayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
RecyclerView myRecyclerView= (RecyclerView) findViewById(R.id.my_recycler_view);
myRecyclerView.setLayoutManager(layoutManager);
关于java - 我想在我的 Homefragment.java 类的 recyclerview 中添加水平滚动的卡片 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58908944/
我在将 FirestoreUI 与 BottomNavigationBar 连接时遇到问题。我不知道如何实现OnCreateView来修改HomeFragment,如下所示- public class
我正在学习教程,我尝试通过添加适配器将 RecyclerView 添加到其中并在我的 HomeFragment 中显示它,但不幸的是,当我在模拟器上运行该项目时,我的应用程序停止了。 我有我的 Hom
我在这部分代码中遇到错误: private void displayView(int position) { // update the main content by replacing f
我的 Adapter 出错,这是我的代码,错误指向这段代码,它在 HomeFragment.java 上,它说: error: incompatible types: HomeFragment can
这是我的 MainActivity.java 类 package com.example.bottomnavigationdrawer; import androidx.appcompat.app.A
公共(public)类 HomeFragment 扩展 Fragment 实现 HomeView{ private HomeViewModel homeViewModel; public static
我正在尝试通过单击图标打开我在 HomeFragment 的 MainActivity 中创建的 NavigationDrawer。当我单击图标时,我希望抽屉打开...即使我将它放在我的 MainAc
我是一名优秀的程序员,十分优秀!