当我试图在片段中诋毁崩溃栏时,它不会崩溃,但是当我在一个简单的活动中尝试相同的代码时,它工作正常,我想在片段(ProfileFragment)中使用相同的设计,没有错误发生它只是只是显示,但它没有崩溃,我想让它工作正常请帮助我,看看我想要暗示我的代码。
这是我的XML
<android.support.constraint.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"
android:clickable="true"
android:focusable="true"
tools:context="com.turbo.ashish.hexon.BottomNavFragment.ProfileFragment">
<!-- TODO: Update blank fragment layout -->
<android.support.design.widget.AppBarLayout
android:id="@+id/idProfileWallappbar"
android:layout_width="match_parent"
android:layout_height="238dp">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/idcollapsbarlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorAccent"
app:expandedTitleMarginBottom="20dp"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="20dp"
app:layout_scrollFlags="exitUntilCollapsed|scroll"
app:title="@string/title_profile">
<ImageView
android:id="@+id/idImageViewCollapsingToolbarLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<android.support.v7.widget.Toolbar
android:id="@+id/idtoolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/custColtransparante"
app:layout_collapseMode="pin">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<Button
android:id="@+id/idFragBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="304dp"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
My Fragment Java File ..
package com.turbo.ashish.hexon.BottomNavFragment;
import android.net.Uri;
import android.os.Bundle;
import android.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.storage.FirebaseStorage;
import com.google.firebase.storage.StorageReference;
import com.turbo.ashish.hexon.R;
import static android.widget.Toast.LENGTH_LONG;
public class ProfileFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
Log.d("Working","Wasd");
View fragView = inflater.inflate(R.layout.fragment_profile,container,false);
fragView.findViewById(R.id.idFragBtn).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(getActivity(),"asd",Toast.LENGTH_LONG).show();
}
});
return fragView;
}
}
但是,在Fragment中,Collapsing栏布局始终保持不变,我想让这个collapsingbar处理片段(ProfileFragment)..
我的平台活动,我加载片段如:
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= new BottomNavigationView.OnNavigationItemSelectedListener() {
@SuppressLint("ResourceType")
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
android.app.FragmentTransaction ft = getFragmentManager().beginTransaction();
switch (item.getItemId()){
case R.id.idNavContacts:
toolbar.setTitle("Contacts");
ft.replace(R.id.idFrameContainer, new ContactsFragment(), "Contacts Ftagment").commit();
return true;
case R.id.idNavPerson:
toolbar.setTitle("Profile");
ft.replace(R.id.idFrameContainer,new ProfileFragment(), "Profile Fragment").commit();
return true;
case R.id.idNavGroups:
toolbar.setTitle("Groups");
ft.replace(R.id.idFrameContainer,new GroupsFragment(), "Groups Fragment").commit();
return true;
case R.id.idNavFeeds:
toolbar.setTitle("Feeds");
ft.replace(R.id.idFrameContainer, new FeedskFragment(), "Feeds Fragment").commit();
return true;
}
return false;
}
};
加载片段没有问题,但是Collapsing栏没有响应(没有滑动),我希望以片段形式发生。
活动XML
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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="com.turbo.ashish.hexon.Platform">
<FrameLayout
android:id="@+id/idFrameContainer"
android:layout_width="match_parent"
android:layout_height="454dp">
</FrameLayout>
<android.support.design.widget.BottomNavigationView
android:id="@+id/idBottomNav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="?android:attr/windowBackground"
app:itemBackground="@color/WHITE"
android:foreground="?attr/selectableItemBackground"
app:itemIconTint="@color/deepViolate"
app:itemTextColor="@color/deepViolate"
app:menu="@menu/navigation">
</android.support.design.widget.BottomNavigationView>
</android.support.design.widget.CoordinatorLayout>
答案 0 :(得分:0)
为什么我的折叠工具栏布局不起作用?
您希望折叠工具栏在约束布局中工作吗?
首先,要使折叠工具栏正常工作
android.support.design.widget.CoordinatorLayout
作为 root布局。
答案 1 :(得分:0)
在android.support.constraint.ConstraintLayout的代码instand下面的xml文件中更改为room xml标记..
<android.support.design.widget.CoordinatorLayout>