Когда я запускаю свое приложение на виртуальном устройстве, это похоже на панель инструментов ekstra, которая появляется в моей активности.
Это действие с вложенной прокруткой и сворачивающейся панелью инструментов. Вся анимация и все кнопки работают отлично, но похоже, что это добавляет пространство ekstra и это точно размер свернутой / обычной панели инструментов.
Если я изменю координатуLayout layout_height на "wrap_content", дополнительное пространство будет идти внизу экрана, а не прямо под правильной панелью инструментов.
Кто-нибудь может увидеть, в чем проблема? Я попробовал множество различных настроек сейчас.
Не свернутая панель инструментов с изображением
Свернутая панель инструментов
Вот код для действия:
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);
}
}
Вот xml действия:
<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>
Вот XML-файл 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>
и, наконец, манифест:
<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>