I want to add ScrollView to my navigation drawer, I first tried to but the linear layout as a child under Scrollview, but when I opened my fragment, the navigation drawer shows under my fragment. I want to have my fragments untouched, whereas the navigation drawer does now show behind the fragments, and the navigation drawer has scrollview.
drawer code:
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>
example of scrolling I want for the main content:
when the main content is scrollable, it shows under the first fragment
I think you have to set
<com.google.android.material.navigation.NavigationView
...
android:fitsSystemWindows="true"
android:isScrollContainer="true"
... />
Had a lot of help and figured it out.
Add scrollview to separate fragment and incorporate in the onCreate.
'''
ScrollView
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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<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>
Related
i have this problem for a while now seem i cant solve it
HomeFragment.java
public class HomeFragment extends Fragment {
/*- 01 Class Variables -------------------------------------------------------------- */
private View mainView;
private Cursor listCursor;
// Action buttons on toolbar
private MenuItem menuItemAddFood;
// Holding variables
private String currentDateYear = "";
private String currentDateMonth = "";
private String currentDateDay = "";
private String currentFoodId;
private String currentFoodName;
private String currentFdId;
private boolean lockPortionSizeByPcs;
private boolean lockPortionSizeByGram;
/*- 02 Fragment Variables ----------------------------------------------------------- */
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
// TODO: Rename and change types of parameters
private String mParam1;
private String mParam2;
private OnFragmentInteractionListener mListener;
/*- 03 Constructur ------------------------------------------------------------------ */
public HomeFragment() {
// Required empty public constructor
}
/*- 04 Creating Fragment ------------------------------------------------------------- */
// TODO: Rename and change types and number of parameters
public static HomeFragment newInstance(String param1, String param2) {
HomeFragment fragment = new HomeFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
//OnCREATEEEEEE
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
//---------Set Title----------
((MainActivity)getActivity()).getSupportActionBar().setTitle("Home");
}
/*- 05 on Activity Created ---------------------------------------------------------- */
// Run methods when started
// Set toolbar menu items
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
/* Set title */
((MainActivity)getActivity()).getSupportActionBar().setTitle("Home");
// getDataFromDbAndDisplay
initializeHome();
// Create menu
setHasOptionsMenu(true);
} // onActivityCreated
/*- 06 On create view ---------------------------------------------------------------- */
// Sets main View variable to the view, so we can change views in fragment
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mainView = inflater.inflate(R.layout.fragment_home, container, false);
return mainView;
}
/*- 07 set main view ----------------------------------------------------------------- */
// Changing view method in fragmetn
private void setMainView(int id){
LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mainView = inflater.inflate(id, null);
ViewGroup rootView = (ViewGroup) getView();
rootView.removeAllViews();
rootView.addView(mainView);
}
/*- 08 on Create Options Menu -------------------------------------------------------- */
// Creating action icon on toolbar
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
// Inflate menu
MenuInflater menuInflater = ((MainActivity)getActivity()).getMenuInflater();
inflater.inflate(R.menu.menu_home, menu);
// ((MainActivity)getActivity()).getMenuInflater().inflate(R.menu.menu_home, menu);
// Assign menu items to variables
menuItemAddFood = menu.findItem(R.id.menu_action_add_food);
}
/*- 09 on Options Item Selected ------------------------------------------------------ */
// Action icon clicked on
// Menu
#Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
int id = menuItem.getItemId();
if (id == R.id.menu_action_add_food) {
AddFoodToDiarySelectedMealNumber();
}
return super.onOptionsItemSelected(menuItem);
}
MainActivty
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener,
AddFoodToDiaryFragment.OnFragmentInteractionListener,
CategoriesFragment.OnFragmentInteractionListener,
FoodFragment.OnFragmentInteractionListener,
GoalFragment.OnFragmentInteractionListener,
HomeFragment.OnFragmentInteractionListener,
ProfileFragment.OnFragmentInteractionListener{
private AppBarConfiguration mAppBarConfiguration;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/* Toolbar */
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
/* Inialize fragmet */
Fragment fragment = null;
Class fragmentClass = null;
fragmentClass = HomeFragment.class;
try {
fragment = (Fragment) fragmentClass.newInstance();
} catch (Exception e) {
e.printStackTrace();
}
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.flContent, fragment).commit();
/* Navigation */
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
// Navigation items
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
//stetho---
Stetho.initializeWithDefaults(this);
new OkHttpClient.Builder().addNetworkInterceptor(new StethoInterceptor()).build();
/* Database */
DBAdapter db = new DBAdapter(this);
db.open();
/* Setup for food */
// Count rows in food
int numberRows = db.count("food");
if(numberRows < 1){
// Run setup
Toast.makeText(this, "Loading setup...", Toast.LENGTH_LONG).show();
DBSetupInsert setupInsert = new DBSetupInsert(this);
setupInsert.insertAllCategories();
setupInsert.insertAllFood();
Toast.makeText(this, "Setup completed!", Toast.LENGTH_LONG).show();
}
//check if there users in user table
//count rows in user table
numberRows = db.count("users");
Intent intent;
if(numberRows <1 ){
//sign Up
Toast.makeText(this, " you only few steps away from Signing up ...!", Toast.LENGTH_LONG).show();
intent = new Intent(MainActivity.this, SignUp.class);
startActivity(intent);
}else{
intent = new Intent(MainActivity.this, EditProfileGoal.class);
startActivity(intent);
}
db.close();
}
home_fragment.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
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="fill_parent"
android:layout_height="fill_parent"
android:fitsSystemWindows="true">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="18dp"
android:layout_marginRight="18dp"
android:layout_marginBottom="18dp"
android:layout_marginLeft="18dp">
<TextView
android:id="#+id/text_home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<!-- Breakfast -->
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableRow
android:id="#+id/tableRowHeadlineBreakfast"
android:layout_width="fill_parent"
android:background="#A9A9A9 "
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imageViewAddBreakfast"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/ic_menu_add" />
<TextView
android:id="#+id/textViewHeadlineBreakfast"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="80"
android:layout_marginBottom="10dp"
android:text="#string/break_fast"
android:textSize="18sp" />
<TextView
android:id="#+id/textViewEnergyBreakfast"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="10"
android:text="#string/energy"
android:textSize="18sp" />
</TableRow>
</TableLayout>
<TableLayout
android:id="#+id/tableLayoutBreakfastItems"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TableLayout>
<!-- //Breakfast -->
<TextView
android:layout_width="match_parent"
android:layout_height="3dp"
android:id="#+id/textView"
android:background="#000"></TextView>
<!-- Lunch -->
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableRow
android:id="#+id/tableRowHeadlineLunch"
android:layout_width="fill_parent"
android:background="#A9A9A9 "
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imageViewAddLunch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/ic_menu_add" />
<TextView
android:id="#+id/textViewHeadlineLunch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="80"
android:layout_marginBottom="10dp"
android:text="#string/lunch"
android:textSize="18sp" />
<TextView
android:id="#+id/textViewEnergyLunch"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="10"
android:text="#string/energy"
android:textSize="18sp" />
</TableRow>
</TableLayout>
<TableLayout
android:id="#+id/tableLayoutLunchItems"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TableLayout>
<!-- //Lunch -->
<TextView
android:layout_width="match_parent"
android:layout_height="3dp"
android:background="#000"></TextView>
<!-- Before training -->
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableRow
android:id="#+id/tableRowHeadlineBeforeTraining"
android:layout_width="fill_parent"
android:background="#A9A9A9 "
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imageViewAddBeforeTraining"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/ic_menu_add" />
<TextView
android:id="#+id/textViewHeadlineBeforeTraining"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="80"
android:layout_marginBottom="10dp"
android:text="#string/before_training"
android:textSize="18sp" />
<TextView
android:id="#+id/textViewEnergyBeforeTraining"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="10"
android:text="#string/energy"
android:textSize="18sp" />
</TableRow>
</TableLayout>
<TableLayout
android:id="#+id/tableLayoutBeforeTrainingItems"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TableLayout>
<!-- //BeforeT raining -->
<TextView
android:layout_width="match_parent"
android:layout_height="3dp"
android:background="#000"></TextView>
<!-- After training -->
<TableLayout
android:layout_width="fill_parent"
android:background="#A9A9A9 "
android:layout_height="wrap_content">
<TableRow
android:id="#+id/tableRowHeadlineAfterTraining"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imageViewAddAfterTraining"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/ic_menu_add" />
<TextView
android:id="#+id/textViewHeadlineAfterTraining"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="80"
android:layout_marginBottom="10dp"
android:text="#string/after_training"
android:textSize="18sp" />
<TextView
android:id="#+id/textViewEnergyAfterTraining"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="10"
android:text="#string/energy"
android:textSize="18sp" />
</TableRow>
</TableLayout>
<TableLayout
android:id="#+id/tableLayoutAfterTrainingItems"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TableLayout>
<!-- //After Training -->
<TextView
android:layout_width="match_parent"
android:layout_height="3dp"
android:background="#000"></TextView>
<!-- Dinner -->
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableRow
android:id="#+id/tableRowHeadlineDinner"
android:layout_width="fill_parent"
android:background="#A9A9A9 "
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imageViewAddDinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/ic_menu_add" />
<TextView
android:id="#+id/textViewHeadlineDinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="80"
android:layout_marginBottom="10dp"
android:text="#string/dinnner"
android:textSize="18sp" />
<TextView
android:id="#+id/textViewEnergyDinner"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="10"
android:text="#string/energy"
android:textSize="18sp" />
</TableRow>
</TableLayout>
<TableLayout
android:id="#+id/tableLayoutDinnerItems"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TableLayout>
<!-- //Dinner -->
<TextView
android:layout_width="match_parent"
android:layout_height="3dp"
android:background="#000"></TextView>
<!-- Snacks -->
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableRow
android:id="#+id/tableRowHeadlineSnacks"
android:layout_width="fill_parent"
android:background="#A9A9A9 "
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imageViewAddSnacks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/ic_menu_add" />
<TextView
android:id="#+id/textViewHeadlineSnacks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="80"
android:layout_marginBottom="10dp"
android:text="#string/snacks"
android:textSize="18sp" />
<TextView
android:id="#+id/textViewEnergySnacks"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="10"
android:text="#string/energy"
android:textSize="18sp" />
</TableRow>
</TableLayout>
<TableLayout
android:id="#+id/tableLayoutSnacksItems"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TableLayout>
<!-- //Snacks -->
<TextView
android:layout_width="match_parent"
android:layout_height="3dp"
android:background="#000"></TextView>
<!-- Supper -->
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableRow
android:id="#+id/tableRowHeadlineSupper"
android:layout_width="fill_parent"
android:background="#A9A9A9 "
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imageViewAddSupper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/ic_menu_add" />
<TextView
android:id="#+id/textViewHeadlineSupper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="80"
android:layout_marginTop="10dp"
android:text="#string/supper"
android:textSize="18sp" />
<TextView
android:id="#+id/textViewEnergySupper"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="10"
android:text="#string/energy"
android:textSize="18sp" />
</TableRow>
</TableLayout>
<TableLayout
android:id="#+id/tableLayoutSupperItems"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TableLayout>
<!-- //Supper -->
<TextView
android:layout_width="match_parent"
android:layout_height="3dp"
android:background="#000"></TextView>
<!-- todays reuslt -->
<!-- total -->
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableRow
android:id="#+id/tableRowHeadlineTotal"
android:layout_width="fill_parent"
android:background=" #D3D3D3 "
android:layout_height="wrap_content">
<TextView
android:id="#+id/textViewHeadlineGoalWithActivity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="10dp"
android:text="#string/goal_with_activity"
android:textSize="18sp" />
<TextView
android:id="#+id/textViewFood"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="#string/food_calories"
android:textSize="18sp" />
<TextView
android:id="#+id/textViewSum"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="#string/remaining"
android:textSize="18sp" />
</TableRow>
<!---->
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/headcell"
>
<TextView
android:id="#+id/textViewBodyGoalWithActivity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="10dp"
android:text="#string/goal_with_activity"
android:textSize="18sp" />
<TextView
android:id="#+id/textViewBodyFood"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="#string/food_calories"
android:textSize="18sp" />
<TextView
android:id="#+id/textViewBodyRemain"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="#string/remaining"
android:textSize="18sp" />
</TableRow>
</TableLayout>
<!-- end todays reuslt -->
</LinearLayout>
</ScrollView>
main_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:openDrawer="start">
<include
layout="#layout/app_bar_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<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"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_fragment"
app:menu="#menu/activity_main_drawer" />
</androidx.drawerlayout.widget.DrawerLayout>
the error
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.appdiet33, PID: 6829
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.appdiet33/com.example.appdiet33.MainActivity}: java.lang.IllegalArgumentException: No view found for id 0x7f09009d (com.example.appdiet33:id/flContent) for fragment HomeFragment{35b333b} (1260b40b-35da-49bd-9060-13848371c9d8) id=0x7f09009d}
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.IllegalArgumentException: No view found for id 0x7f09009d (com.example.appdiet33:id/flContent) for fragment HomeFragment{35b333b} (1260b40b-35da-49bd-9060-13848371c9d8) id=0x7f09009d}
at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:305)
i have tried to use getChildFragmentManager() instead of getSupportFragmentManager() like similiar question asked
in HomeFragment
question asked but it didn't work for me
any suggestion please?
Edit:
i have solved turned out i have misspelled the id inside app_bar_main.xml and fixed it
I am unable to click any of my menu items, I cannot swipe from right to left to close the drawer, although, whenever it is opened and I click on the screen it immediately closes.
I have pretty much tried every answer posted to similar questions here on stack overflow and Github:
public class BottomActivity extends AppCompatActivity
implements GestureOverlayView.OnGesturePerformedListener {
RadioGroup radioGroup;
RadioButton Rd1, Rd2, Rd3, Rd4;
DrawerLayout drawer;
#SuppressLint({"RtlHardcoded", "ClickableViewAccessibility"})
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate( savedInstanceState );
setContentView( R.layout.activity_bottom );
new GestureOverlayView( this );
Objects.requireNonNull( getSupportActionBar() ).setDisplayOptions( ActionBar.DISPLAY_SHOW_CUSTOM );
getSupportActionBar().setCustomView( R.layout.abs_layout_home );
radioGroup = findViewById( R.id.radioGroup );
Rd1 = findViewById( R.id.radioButton );
Rd2 = findViewById( R.id.radioButton2 );
Rd3 = findViewById( R.id.radioButton3 );
Rd4 = findViewById( R.id.radioButton4 );
radioGroup.setOnCheckedChangeListener( new RadioGroup.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (Rd1.isChecked()) {
Intent intent = new Intent( getApplicationContext(), BottomActivity.class );
startActivity( intent );
}
if (Rd2.isChecked()) {
Intent intent1 = new Intent( getApplicationContext(), DashBoard.class );
startActivity( intent1 );
}
if (Rd3.isChecked()) {
Intent intent2 = new Intent( getApplicationContext(), SettingsActivity.class );
startActivity( intent2 );
} else {
if (Rd4.isChecked()) {
Intent intent3 = new Intent( getApplicationContext(), Messages.class );
startActivity( intent3 );
}
}
}
} );
}
#Override
public void onBackPressed() {
if (drawer.isDrawerOpen( GravityCompat.START )) {
drawer.closeDrawer( GravityCompat.START );
} else {
super.onBackPressed();
}
}
public void onDrawerSlide() {
DrawerLayout drawerLayout = findViewById( R.id.DrawerLayout);
drawerLayout.addDrawerListener(
new DrawerLayout.DrawerListener() {
#Override
public void onDrawerSlide(#NonNull View view, float v) {
}
#Override
public void onDrawerOpened(#NonNull View view) {
}
#Override
public void onDrawerClosed(#NonNull View view) {
}
#Override
public void onDrawerStateChanged(int i) {
}
}
);
}
#Override
public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.nav_profile:
startActivity( new Intent(BottomActivity.this, ProfileActivity.class));
return true;
case R.id.nav_settings:
startActivity( new Intent( BottomActivity.this, SettingsActivity.class));
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
Here is my navigation drawer XML code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.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"
tools:openDrawer="start"
tools:openNavigationView="start"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleGravity="top"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="#color/colorPrimary"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
android:minHeight="?attr/actionBarSize"
app:layout_collapseMode="pin"/>
</android.support.design.widget.CollapsingToolbarLayout>
<include
layout="#layout/app_bar_nav_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_nav_drawer"
app:menu="#menu/activity_nav_drawer_drawer" />
Here is my activities XML code:
<?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:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_gravity="center"
android:elevation="10dp"
android:foregroundGravity="center"
android:gravity="center"
android:orientation="vertical"
tools:context=".BottomActivity"
tools:targetApi="lollipop"
app:layout_collapseMode="parallax">
<include
android:id="#+id/include"
layout="#layout/activity_drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<RadioGroup
android:id="#+id/radioGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#color/colorPrimary"
android:gravity="bottom"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<RadioButton
android:id="#+id/radioButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="#null"
android:buttonTint="#color/iconColor"
android:checked="true"
android:drawableTop="#drawable/ic_home_black_24dp"
android:padding="10dp"
android:tag="1"
android:text="#string/home"
android:textAlignment="center"
android:textColor="#color/color"
android:textSize="12sp"/>
<RadioButton
android:id="#+id/radioButton2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="#null"
android:buttonTint="#color/uiconColor"
android:drawableTop="#drawable/ic_notifications_black_24dp"
android:padding="10dp"
android:text="#string/notifications"
android:textAlignment="center"
android:textColor="#color/color"
android:textSize="12sp"/>
<RadioButton
android:id="#+id/radioButton3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="#null"
android:buttonTint="#color/uiconColor"
android:drawableTop="#drawable/ic_people_icon"
android:padding="10dp"
android:text="#string/People"
android:textAlignment="center"
android:textColor="#color/color"
android:textSize="12sp"/>
<RadioButton
android:id="#+id/radioButton4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="#null"
android:buttonTint="#color/uiconcolor"
android:drawableTop="#drawable/ic_msg_icon"
android:padding="10dp"
android:text="#string/Messages"
android:textAlignment="center"
android:textColor="#color/color"
android:textSize="12sp"/>
</RadioGroup>
</android.support.design.widget.CoordinatorLayout>
In BottomActivity add this in your onCreate:
NavigationView nav_view;
nav_view = findViewById(R.id.nav_view); //select nav_view from activity_drawer_layout
nav_view.setNavigationItemSelectedListener(this);
In activity_drawer_layout.xml put the NavigationView above the closing tag for the DrawerLayout.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".DrawerLayout"
android:id="#+id/DrawerLayout">
<include
android:id="#+id/include"
layout="#layout/app_bar_nav_drawer"
android:layout_width="0dp"
android:layout_height="0dp" />
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="0dp"
android:layout_height="673dp"
android:padding="16dp"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/cv">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/name" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/age"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:layout_constraintBottom_toBottomOf="#+id/nav_header" />
<include
android:id="#+id/include"
layout="#layout/app_bar_nav_drawer"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:layout_gravity="start"
android:clickable="true"
android:focusable="true"
android:orientation="vertical"
app:headerLayout="#layout/nav_header_nav_drawer"
app:menu="#menu/activity_nav_drawer_drawer" />
</android.support.v4.widget.DrawerLayout>
I want to add collapsing toolbar in my app. I want to add a graph layout also image view and text views inside the collapsing toolbar layout. Like this image.
This graph is in collapsing toolbar layout. When we do scroll up graph goes up and remains as a toolbar.
Now I am trying to add views under collapsing toolbar layout. But I am not able to move them and align them. How to do?
Layout:
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/parentPanel"
xmlns:fab="http://schemas.android.com/apk/res-auto">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="250dp"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:id="#+id/appbar">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_reorder_black_48dp"
android:id="#+id/navigationMenu" />
</android.support.v7.widget.Toolbar>
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_check_box_white_24dp"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffe5e5e5"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:id="#+id/scrollView">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="10dp">
<include layout="#layout/card_layout" />
<include layout="#layout/card_layout" />
<include layout="#layout/card_layout" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
app:layout_anchor="#id/appbar"
app:layout_anchorGravity="bottom|right|end"
style="#style/FabStyle"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_anchor = "#id/parentPanel"
app:layout_anchorGravity = "bottom|right|end"
android:padding="20dp"
android:weightSum="1">
<com.github.clans.fab.FloatingActionMenu
android:id="#+id/menu1"
android:layout_width="match_parent"
android:layout_height="219dp"
android:paddingRight="10dp"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
fab:menu_labels_ellipsize="end"
fab:menu_labels_singleLine="true"
fab:menu_backgroundColor="#ccffffff"
fab:menu_fab_label="Menu label"
android:layout_gravity="bottom">
<com.github.clans.fab.FloatingActionButton
android:id="#+id/fab1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_add_white_24dp"
fab:fab_size="mini"
fab:fab_label="addList" />
<com.github.clans.fab.FloatingActionButton
android:id="#+id/fab2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_list_white_24dp"
fab:fab_size="mini"
fab:fab_label="list1" />
<com.github.clans.fab.FloatingActionButton
android:id="#+id/fab3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_list_white_24dp"
fab:fab_size="mini"
fab:fab_label="list2" />
<com.github.clans.fab.FloatingActionButton
android:id="#+id/fab4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_list_white_24dp"
fab:fab_size="mini"
fab:fab_label="list3" />
</com.github.clans.fab.FloatingActionMenu>
</LinearLayout>
Activity:
public class MainActivity extends AppCompatActivity {
private CollapsingToolbarLayout collapsingToolbarLayout = null;
private FloatingActionButton fab1;
private FloatingActionButton fab2;
private FloatingActionButton fab3;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
final FloatingActionMenu menu1 = (FloatingActionMenu) findViewById(R.id.menu1);
collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
collapsingToolbarLayout.setTitle("List Title");
ImageView navigationMenu = (ImageView)findViewById(R.id.navigationMenu);
fab1 = (FloatingActionButton) findViewById(R.id.fab1);
fab2 = (FloatingActionButton) findViewById(R.id.fab2);
fab3 = (FloatingActionButton) findViewById(R.id.fab3);
fab1.setOnClickListener(clickListener);
fab2.setOnClickListener(clickListener);
fab3.setOnClickListener(clickListener);
navigationMenu.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this,NavigationMenuActivity.class));
overridePendingTransition(R.anim.left, R.anim.enter);
}
});
menu1.setOnMenuButtonClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (menu1.isOpened()) {
Toast.makeText(MainActivity.this, menu1.getMenuButtonLabelText(), Toast.LENGTH_SHORT).show();
}
menu1.toggle(true);
}
});
menu1.setClosedOnTouchOutside(true);
dynamicToolbarColor();
toolbarTextAppernce();
}
private void dynamicToolbarColor() {
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.b);
Palette.from(bitmap).generate(new Palette.PaletteAsyncListener() {
#Override
public void onGenerated(Palette palette) {
collapsingToolbarLayout.setContentScrimColor(palette.getMutedColor(getResources().getColor(R.color.colorPrimary)));
collapsingToolbarLayout.setStatusBarScrimColor(palette.getMutedColor(getResources().getColor(R.color.colorPrimaryDark)));
}
});
}
private void toolbarTextAppernce() {
collapsingToolbarLayout.setCollapsedTitleTextAppearance(R.style.collapsedappbar);
collapsingToolbarLayout.setExpandedTitleTextAppearance(R.style.expandedappbar);
}
private View.OnClickListener clickListener = new View.OnClickListener() {
#Override
public void onClick(View v) {
String text = "";
switch (v.getId()) {
case R.id.fab1:
text = fab1.getLabelText();
break;
case R.id.fab2:
text = fab2.getLabelText();
fab2.setVisibility(View.GONE);
break;
case R.id.fab3:
text = fab3.getLabelText();
fab2.setVisibility(View.VISIBLE);
break;
}
}
};
}
Now I have a single image view inside collapsing toolbar layout and that I can't move or align. How to align view and add views under collapsing toolbar?
Thank you..
CollapsingToolbarLayout is a subclass of FrameLayout.
For maximum flexibility, put all your widgets inside a LinearLayout or RelativeLayout and make it the only child of the CollapsingToolbarLayout. Also for best results with vertical sizing, set the height to a specific dimension.
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="#dimen/graph_toolbar_height"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_collapseMode="parallax">
<!-- graph UI here -->
</RelativeLayout>
</android.support.design.widget.CollapsingToolbarLayout>
Create a layout inside collapsingtoolbarlayout and add your views in there.
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="#color/colorPrimary"
app:expandedTitleGravity="bottom|center_horizontal"
app:expandedTitleMarginBottom="64dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="230dp"
android:scaleType="centerCrop"
android:src="#drawable/ic_about"
app:layout_collapseMode="parallax" />
<TextView
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#color/colorAccent"
android:text="#string/about_title"
android:textSize="#dimen/text_size_large" />
</LinearLayout>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:layout_marginTop="#dimen/status_bar_height"
app:layout_collapseMode="pin"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
I'm trying to implement a Slinding Menu by using Pager Sliding Tab Strip (com.astuetz:pagerslidingtabstrip).
I set up my xml layout of the main screen:
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight=".97">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/logo_b"
android:src="#drawable/logo_b"
android:layout_weight=".05"
android:layout_gravity="right"
android:layout_marginRight="-15dp" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/scrollMe"
android:layout_weight=".95"
android:fillViewport="false">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal">
<com.astuetz.PagerSlidingTabStrip
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="48dip"
app:pstsIndicatorColor="#19B5FE"
app:pstsShouldExpand="true"
app:pstsTextAllCaps="false"
app:pstsIndicatorHeight="1dp"
/>
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</ScrollView>
</LinearLayout>
This xml is included into another View, but it handle the View Pager.
To handle the init of ViewPager and PagerSlidingTapStrip i have a FragmentActivity where during onCreate i have:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sliding_menu);
pager = (ViewPager) findViewById(R.id.pager);
CustomPagerAdapteradapter = new CustomPagerAdapter(getSupportFragmentManager());
adapter.setContext(getApplicationContext());
pager.setAdapter(adapter);
tabs = (PagerSlidingTabStrip) findViewById(R.id.tabs);
tabs.setViewPager(pager);
}
And the adapter is:
public static class CustomPagerAdapteradapter extends FragmentPagerAdapter implements IconTabProvider {
private int[] ICONS = {
R.drawable.icon_menu0,
R.drawable.icon_menu1,
R.drawable.icon_menu2,
R.drawable.icon_menu3,
R.drawable.icon_menu4
};
private static Context CONTEXT;
private Fragment fragment[] = new Fragment[5];
public CustomPagerAdapteradapter (FragmentManager fm) {
super(fm);
for(int i = 0; i < 5; ++i) {
fragment[i] = Profile.newInstance();
}
}
public void setContext(Context c) { CONTEXT = c; }
#Override
public int getCount() {
return ICONS.length;
}
#Override
public Fragment getItem(int position) {
Toast.makeText(CONTEXT, "" + position, Toast.LENGTH_SHORT).show();
switch (position) {
case 0:
return fragment[position];
case 1:
return fragment[position];
case 2:
return fragment[position];
case 3:
return fragment[position];
case 4:
return fragment[position];
case 5:
return fragment[position];
default:
return fragment[position];
}
}
#Override
public int getPageIconResId(int position) {
return ICONS[position];
}
}
The Profile Fragment xml is:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight=".90">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight=".20">
<!-- Not filled yet -->
</RelativeLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight=".70"
android:background="#drawable/radius_background"
android:layout_margin="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="15dp"
android:textColor="#FFF"
android:textSize="16dp"
android:text="info#example.com"
android:id="#+id/user_mail" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="5dp"
android:textColor="#FFF"
android:textSize="16dp"
android:text="15/10/54"
android:id="#+id/user_birth" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="5dp"
android:textColor="#FFF"
android:textSize="16dp"
android:text="Italy"
android:id="#+id/user_country" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="5dp"
android:textColor="#FFF"
android:textSize="16dp"
android:text="Pa"
android:id="#+id/user_town_short" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="5dp"
android:textColor="#FFF"
android:textSize="16dp"
android:text="Palermo"
android:id="#+id/user_town" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="5dp"
android:textColor="#FFF"
android:textSize="16dp"
android:text="Male"
android:id="#+id/user_sex" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight=".05">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:textColor="#FFF"
android:background="#18333E"
android:text="Edit/Update Data"
android:id="#+id/updateData"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
Profile fragment onCreateView just inflate the xml:
return inflater.inflate(R.layout.fragment_profile, container, false);
Even if the code seems to be ok, I never see profile on the View Pager. What's wrong?
Final answer: remove the ScrollView as it is blocking with ViewPager.
I am working on ViewPager. I wrote code which can create ViewPager and also I have some java class, but I want my ViewPager must be below the layout.
This is a my xml code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fa6a6a"
>
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#171717" >
<ImageButton
android:id="#+id/menu_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="12dp"
android:background="#drawable/ic_launcher" />
<ImageView
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="7.0mm"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="#drawable/ic_launcher" />
<ToggleButton
android:id="#+id/button_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="12dp"
android:background="#drawable/ic_launcher"
android:padding="2dip"
android:textOff=""
android:textOn="" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_below="#+id/relativeLayout1" >
<android.support.v4.view.ViewPager
android:id="#+id/vp_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/relativeLayout1" >
</android.support.v4.view.ViewPager>
</RelativeLayout>
This is a my java code:
public class MainActivity extends FragmentActivity implements
ActionBar.TabListener {
private ViewPager viewPager;
private TabsPagerAdapter mAdapter;
private ActionBar actionBar;
// Tab titles
private String[] tabs = { "test1", "test2", "test3", "test4",
"test5" };
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
viewPager = (ViewPager) findViewById(R.id.vp_main);
actionBar = getActionBar();
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
mAdapter = new TabsPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(mAdapter);
actionBar.setHomeButtonEnabled(false);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// Adding Tabs
for (String tab_name : tabs) {
actionBar.addTab(actionBar.newTab().setText(tab_name)
.setTabListener(this));
}
/**
* on swiping the viewpager make respective tab selected
* */
viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
#Override
public void onPageSelected(int position) {
actionBar.setSelectedNavigationItem(position);
}
#Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
#Override
public void onPageScrollStateChanged(int arg0) {
}
});
}
#Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
}
#Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
// on tab selected
// show respected fragment view
viewPager.setCurrentItem(tab.getPosition());
}
#Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
}
}
result it like this
I want my viewpager(actionBar)should be rendered below the layout
Check It Out,
It will help u..
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fa6a6a" >
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#171717" >
<ImageButton
android:id="#+id/menu_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="12dp"
android:background="#drawable/ic_launcher" />
<ImageView
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="7.0mm"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="#drawable/ic_launcher" />
<ToggleButton
android:id="#+id/button_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="12dp"
android:background="#drawable/ic_launcher"
android:padding="2dip"
android:textOff=""
android:textOn="" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_below="#+id/relativeLayout1" >
<android.support.v4.view.ViewPager
android:id="#+id/vp_main"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</android.support.v4.view.ViewPager>
</RelativeLayout>
</RelativeLayout>
Try this :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fa6a6a" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true">
<android.support.v4.view.ViewPager
android:id="#+id/vp_main"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v4.view.ViewPager>
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#171717" >
<ImageButton
android:id="#+id/menu_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="12dp"
android:background="#drawable/ic_launcher" />
<ImageView
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="7.0mm"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="#drawable/ic_launcher" />
<ToggleButton
android:id="#+id/button_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="12dp"
android:background="#drawable/ic_launcher"
android:padding="2dip"
android:textOff=""
android:textOn="" />
</RelativeLayout>
</RelativeLayout>
Also dont forget to clean your project . Hope it helps