When I start my application on a virtual device it is like an ekstra toolbar appears on my activity. It is an activity with nested scrollview and collapsing toolbar. All the animations and all the buttons works perfectly, but it seems like it adds ekstra space and it is exactly the size of a collapsed/regular toolbar.
If I change the coordinatorLayout layout_height to "wrap_content" the extra space will go to the bottom of the screen instead of being right under the correct toolbar.
Can anyone see what the problem is? I have tried a plethora of different settings now.
Non collapsed toolbar with imageview Collapsed toolbar
Heres the code for the activity:
public class algorithms_abcde extends AppCompatActivity {
CollapsingToolbarLayout collapsingToolbarLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_algorithms_abcde);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
collapsingToolbarLayout = findViewById(R.id.collapsingToolbar);
collapsingToolbarLayout.setTitle(getString(R.string.btn_txt_abcde));
collapsingToolbarLayout.setExpandedTitleColor(getResources().getColor(android.R.color.transparent));
}
@Override
public boolean onCreateOptionsMenu(Menu menu){
//Inflate the menu; This adds it to the actionba
getMenuInflater().inflate(R.menu.menu_other, menu);
return true;
}
// Determines which button has been pressed.
@Override
public boolean onOptionsItemSelected(MenuItem item){
//Switch case to handle item presses on the action bar
switch (item.getItemId()) {
case android.R.id.home:
this.finish();
return true;
case R.id.action_home:
Intent intent = new Intent(this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
return true;
}
return super.onOptionsItemSelected(item);
}
}
Here is the xml of the activity:
<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=".algorithms_abcde"
android:layout_gravity="bottom">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsingToolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|snap|exitUntilCollapsed"
app:contentScrim="@color/colorVeryLight"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
android:fitsSystemWindows="true"
>
<ImageView
android:id="@+id/headLine"
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_marginLeft="60dp"
android:layout_marginRight="60dp"
android:fitsSystemWindows="true"
android:src="@drawable/img_abcde_headline"/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@android:color/transparent"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="pin"/>
</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:layout_gravity="bottom"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:background="@android:color/white">
<TextView
android:id="@+id/scrollAbleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:padding="10dp"
android:text="@string/stringtest"/>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
Heres the xml of the themes.xml
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowActionBar">false</item>
<item name="android:buttonStyle">@style/button</item>
<!-- Base application theme. -->
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:background">@color/colorVeryLight</item>
</style>
</resources>
and and lastly the manifest:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".algorithms_opqrst"></activity>
<activity android:name=".algorithms_abcde" />
<activity android:name=".algorithms_activity" />
<activity
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>