gpt4 book ai didi

java - 使用 ScrollView 实现 BottomNavigationView

转载 作者:行者123 更新时间:2023-12-02 02:07:32 24 4
gpt4 key购买 nike

我正在尝试实现一个 BottomNavigationView 并在内容中实现一个 ScrollView。一切都很好,但是当 BottomNavigationView 使用 ScrollView 打开 FrameLayout 时,就不起作用了

这是我的activity_main.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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.panel.roubook.activities.NewBook">


<FrameLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/bottom_navigation"
android:layout_alignParentTop="true">

</FrameLayout>

<android.support.design.widget.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:itemBackground="@color/colorAccent"
app:itemIconTint="@color/colorPrimary"
app:itemTextColor="@color/colorPrimary"
app:menu="@menu/navigation_items" />

</RelativeLayout>

这是我的框架

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:paddingLeft="24dp"
android:paddingRight="24dp">

<ImageView
android:layout_width="wrap_content"
android:layout_height="72dp"
android:layout_marginBottom="5dp"
android:layout_gravity="center_horizontal" />

<!-- Email Label -->
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="0dp">
<EditText android:id="@+id/txtEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:hint="@string/user_email_text" />
</android.support.design.widget.TextInputLayout>

<!-- Password Label -->
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="0dp">
<EditText android:id="@+id/txtPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:hint="@string/user_password"/>
</android.support.design.widget.TextInputLayout>

<!-- Signup Button -->
<android.support.v7.widget.AppCompatButton
android:id="@+id/btn_login"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="0dp"
android:padding="12dp"
android:text="@string/user_btn_login"/>

<TextView android:id="@+id/link_register"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="0dp"
android:text="@string/user_link_to_register"
android:gravity="center"
android:textSize="16dip"/>

<TextView android:id="@+id/link_forgot"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="0dp"
android:text="@string/user_link_forgot_password"
android:gravity="center"
android:textSize="16dip"/>


<!-- Email Label -->
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="0dp">
<EditText android:id="@+id/txtEmail2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:hint="@string/user_email_text" />
</android.support.design.widget.TextInputLayout>

<!-- Email Label -->
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="0dp">
<EditText android:id="@+id/txtEmail3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:hint="@string/user_email_text" />
</android.support.design.widget.TextInputLayout>


<!-- Email Label -->
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="0dp">
<EditText android:id="@+id/txtEmail4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:hint="@string/user_email_text" />
</android.support.design.widget.TextInputLayout>


<!-- Email Label -->
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="0dp">
<EditText android:id="@+id/txtEmail5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:hint="@string/user_email_text" />
</android.support.design.widget.TextInputLayout>

<!-- Email Label -->
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="0dp">
<EditText android:id="@+id/txtEmail6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:hint="@string/user_email_text" />
</android.support.design.widget.TextInputLayout>

</LinearLayout>
</ScrollView>

在我的 MainActivity.java

protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

FragmentManager fragmentManager = getFragmentManager();
final FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_navigation);
bottomNavigationView.setOnNavigationItemSelectedListener(
new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.action_explorer:
return true;

case R.id.action_ready:
return true;

case R.id.action_account:
fragmentTransaction.replace(android.R.id.content , new Account());
fragmentTransaction.commit();
return true;

}
return true;
}
});
}

当我按下帐户时,屏幕会更改为帐户,但 ScrollView 覆盖 BottomNavigationView 并且无法使用 BottonNavigationView 的其他按钮

enter image description here

抱歉我的英语不好。

最佳答案

android.R.id.content 替换为 R.id.content 因为 android.R.id.content 不是您的 ID您在 XML 中定义的 FrameLayout,它是其他 View 的 id。

 bottomNavigationView.setOnNavigationItemSelectedListener(
new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.action_explorer:
return true;

case R.id.action_ready:
return true;

case R.id.action_account:
fragmentTransaction.replace(R.id.content , new Account());
fragmentTransaction.commit();
return true;

}
return true;
}
});

关于java - 使用 ScrollView 实现 BottomNavigationView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50521133/

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