gpt4 book ai didi

java - 如何将 ScrollView 添加到抽屉导航

转载 作者:行者123 更新时间:2023-12-02 01:14:29 26 4
gpt4 key购买 nike

我想将 ScrollView 添加到我的抽屉导航中,我首先尝试将线性布局作为 Scrollview 下的子项,但是当我打开 fragment 时,抽屉导航显示在我的 fragment 下方。我想让我的 fragment 保持不变,而抽屉导航现在确实显示在 fragment 后面,并且抽屉导航具有 ScrollView 。

抽屉代码:

public class drawer_home extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {


private DrawerLayout drawer;
Toolbar toolbar;

TextView mStartDate, mEndDate, mPlan, mDays;
FirebaseAuth firebaseAuth;
FirebaseUser user;
FirebaseDatabase firebaseDatabase;
DatabaseReference databaseReference;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_drawer_home);

toolbar = findViewById(R.id.tb);
mStartDate = findViewById(R.id.startDateTV);
mEndDate = findViewById(R.id.endDateTV);
mPlan = findViewById(R.id.planTV);
mDays = findViewById(R.id.daysTV);

setSupportActionBar(toolbar);
/*TextView textView = (TextView)toolbar.findViewById(R.id.toolbartv);
textView.setText("No Excusas");
getSupportActionBar().setDisplayShowTitleEnabled(false);*/

drawer = findViewById(R.id.drawer_layout);
NavigationView navigationView = findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);

ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();

if(savedInstanceState == null) {

getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
new androidx.fragment.app.Fragment()).commit();
navigationView.setCheckedItem(R.id.nav_homeMain);
}
firebaseAuth = FirebaseAuth.getInstance();
user = firebaseAuth.getCurrentUser();
firebaseDatabase = FirebaseDatabase.getInstance();
databaseReference = firebaseDatabase.getReference("Users");
Query query = databaseReference.orderByChild("email").equalTo(user.getEmail());
query.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {

//checkc until requiered data get
for (DataSnapshot ds : dataSnapshot.getChildren()) {

String startdate = "Fecha de Inicio = " + ds.child("Start Date").getValue();
String enddate = "Fecha de Salida = " + ds.child("End Date").getValue();
String plan = "Plan = " + ds.child("Plan").getValue();
String days = "Tu plan acaba en " + ds.child("Days Left").getValue() +" dias ";


mStartDate.setText(startdate);
mEndDate.setText(enddate);
mPlan.setText(plan);
mDays.setText(days);


}
}

@Override
public void onCancelled(@NonNull DatabaseError databaseError) {

}

});

}


@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.nav_homeMain:
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
new androidx.fragment.app.Fragment()).commit();
break;
case R.id.nav_qr:
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
new QRcodeFragment()).commit();
break;
case R.id.nav_profile:
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
new UserProfile()).commit();
break;
case R.id.nav_order:
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
new OrdersActivity()).commit();
break;
case R.id.nav_nutrition:
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
new NutritionActivity()).commit();
break;
case R.id.nav_chat:
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
new ContactActivity()).commit();
break;
case R.id.nav_coach:
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
new CoachesActivity()).commit();
break;
case R.id.nav_information:
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
new AboutUsActivity()).commit();
break;
}

drawer.closeDrawer(GravityCompat.START);
return true;
}

@Override
public void onBackPressed() {
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}


}

}

xml:

<androidx.drawerlayout.widget.DrawerLayout
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:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:background="@drawable/homebcgself"
tools:context=".drawer_home"
tools:openDrawer="start">


<LinearLayout

android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.appcompat.widget.Toolbar
android:id="@+id/tb"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:background="@drawable/toolbar_bg"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

<TextView
android:id="@+id/toolbartv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="cursive"
android:layout_gravity="center"
android:ellipsize="end"
android:gravity="center"
android:maxLines="1"
android:text="No Excusas"
android:textAlignment="center"
android:textAllCaps="true"
android:textColor="#ffffff"
android:textSize="40sp"
android:textStyle="bold" />

</androidx.appcompat.widget.Toolbar>


<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<TextView
android:id="@+id/startDateTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginTop="200dp"
android:textColor="@color/colorWhite"
android:textSize="30sp"
android:textStyle="bold" />


<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/colorWhite" />


<TextView
android:id="@+id/endDateTV"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30sp"
android:textStyle="bold"
android:layout_marginStart="5dp"
android:textColor="@color/colorWhite"/>


<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/colorWhite" />


<TextView
android:id="@+id/planTV"
android:layout_width="match_parent"
android:textSize="30sp"
android:layout_height="wrap_content"
android:textStyle="bold"
android:layout_marginStart="5dp"
android:textColor="@color/colorWhite"/>


<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/colorWhite" />



<TextView
android:id="@+id/daysTV"
android:layout_width="match_parent"
android:textSize="30sp"
android:layout_height="wrap_content"
android:textStyle="bold"
android:layout_marginStart="5dp"
android:textColor="@color/colorWhite"/>


<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/colorWhite" />




</LinearLayout>




<com.google.android.material.navigation.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/nav_header"
app:menu="@menu/drawer_menu" />


</androidx.drawerlayout.widget.DrawerLayout>

我想要的主要内容滚动示例:

screen 1

screen 2

当主要内容可滚动时,它显示在第一个 fragment 下方

error part 1

error part 2

error part 3/3

最佳答案

我认为你必须设置

<com.google.android.material.navigation.NavigationView
...
android:fitsSystemWindows="true"
android:isScrollContainer="true"
... />

关于java - 如何将 ScrollView 添加到抽屉导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58887372/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com