Having implemented a FloatingSearchView inside my AppBarLayout like is the case with Google Play App I am faced with one challenge of the suggestion not showing up properly when searching. This is my xml

<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.support.design.widget.AppBarLayout
    android:id="@+id/appbarLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:elevation="0dp" >

    <com.arlib.floatingsearchview.FloatingSearchView
        android:id="@+id/search_view"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        app:floatingSearch_close_search_on_keyboard_dismiss="true"
        app:floatingSearch_leftActionMode="showHamburger"
        app:floatingSearch_menu="@menu/main"
        app:floatingSearch_searchBarMarginLeft="5dp"
        app:floatingSearch_searchBarMarginRight="5dp"
        app:floatingSearch_searchBarMarginTop="5dp"
        app:floatingSearch_searchHint="@string/main_title"
        app:floatingSearch_showSearchKey="false"
        app:floatingSearch_suggestionsListAnimDuration="250" />

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabGravity="fill"
        app:tabMode="scrollable"
        app:tabPaddingEnd="16dp"
        app:tabPaddingStart="16dp"
        app:tabTextAppearance="@style/TabLayoutStyle" />

</android.support.design.widget.AppBarLayout>

<com.oyonde.myapp.components.CustomViewPager
    android:id="@+id/mainViewPager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

in java code I have tried to do this when searching

private void searchViewDisplay(boolean isSearching) {        
    FloatingSearchView mSearchView = findViewById(R.id.search_view);
    AppBarLayout appbarLayout = findViewById(R.id.appbarLayout);
    TabLayout tabLayout = findViewById(R.id.tabs);
    ViewPager viewPager = findViewById(R.id.mainViewPager);

    ViewGroup.LayoutParams appbarParams = appbarLayout.getLayoutParams();
    ViewGroup.LayoutParams searchParams = mSearchView.getLayoutParams();

    if (isSearching) {
        tabLayout.setVisibility(View.GONE);
        viewPager.setVisibility(View.GONE);

        AppBarLayout.LayoutParams aprams = new AppBarLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

        appbarParams.height = 500;
        searchParams.height = 500;
    } else {
        tabLayout.setVisibility(View.VISIBLE);
        viewPager.setVisibility(View.VISIBLE);

        appbarParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        searchParams.height = 120;
    }

    appbarLayout.setLayoutParams(appbarParams);
    mSearchView.setLayoutParams(searchParams);
}

I would appreciate some help to get this working right since I am able to hide some elements like the viewpager.

So far I tried to have a my appbarlayout use match_parent height in xml and the floating search view the same and the suggestions appeared as desired but now i want to change their heights pragmatically.

1 Answers

1
Community On Best Solutions

I think you trying to solve your problem pragmatically in your java code is not the best way for this issue. Try to use xml as much as you can like this.

<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:fitsSystemWindows="true" >

    <View
        android:id="@+id/header_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/colorPrimary" />

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

        <com.oyonde.myapp.components.CustomViewPager
            android:id="@+id/mainViewPager"
            android:layout_marginTop="105dp"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />

        <android.support.design.widget.AppBarLayout
            android:id="@+id/appbarLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="60dp"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:elevation="0dp">

            <android.support.design.widget.TabLayout
                android:id="@+id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="0dp"
                app:tabGravity="fill"
                app:tabMode="scrollable"
                app:tabPaddingEnd="16dp"
                app:tabPaddingStart="16dp"
                app:tabTextAppearance="@style/TabLayoutStyle" />

        </android.support.design.widget.AppBarLayout>

        <com.arlib.floatingsearchview.FloatingSearchView
            android:id="@+id/search_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:floatingSearch_close_search_on_keyboard_dismiss="true"
            app:floatingSearch_leftActionMode="showHamburger"
            app:floatingSearch_menu="@menu/main"
            app:floatingSearch_searchBarMarginLeft="5dp"
            app:floatingSearch_searchBarMarginRight="5dp"
            app:floatingSearch_searchBarMarginTop="5dp"
            app:floatingSearch_searchHint="@string/main_title"
            app:floatingSearch_showSearchKey="false"
            app:floatingSearch_suggestionsListAnimDuration="250" />

    </FrameLayout>

</android.support.design.widget.CoordinatorLayout>

Using FrameLayout should solve your problem here