У меня есть приложение, основанное на тривиальном диске v2 , которое загружает следующее представление в своей основной деятельности:
layout / activity_wallpaper.xml:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@id/screen_main">
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<!--Include loading screen-->
<include layout="@layout/loading_indicator"/>
</LinearLayout>
</FrameLayout>
отображается как:
Некоторые элементы списка можно приобрести и начать новое действие при нажатии, что, в свою очередь, создаетфрагмент диалога из макета:
layout / acqu_fragment.xml:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/acquire_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/list_bg_color">
<include layout="@layout/loading_indicator" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="@color/primary_color"
android:layout_gravity="top"
android:minHeight="?android:attr/actionBarSize"
style="@style/ToolbarStyle"
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark" />
<TextView
android:id="@+id/error_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:padding="@dimen/single_padding"
android:visibility="gone" />
<android.support.v7.widget.RecyclerView
android:layout_marginTop="?android:attr/actionBarSize"
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" />
</FrameLayout>
отображается как:
Каждая запись во фрагменте диалога состоит из двух строк (заголовок, запись):
layout / sku_details_row_header.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
style="@style/CardViewStyle"
android:layout_height="@dimen/sku_details_row_header_height"
android:focusable="true"
app:cardBackgroundColor="@color/row_header_bg_color">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fontFamily="sans-serif-medium"
android:layout_marginEnd="@dimen/double_padding"
android:layout_marginStart="@dimen/double_padding"
android:gravity="start|center_vertical"
android:textSize="@dimen/sku_details_row_text_size"/>
</android.support.v7.widget.CardView>
отображается как:
и layout / sku_details_row.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
style="@style/CardViewStyle"
android:layout_height="@dimen/sku_details_row_height"
app:cardBackgroundColor="@color/row_bg_color">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:background="?android:attr/selectableItemBackground"
android:padding="@dimen/sku_details_row_padding">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="@+id/title"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:ellipsize="end"
android:maxLines="1"
android:textSize="@dimen/sku_details_row_text_size"
android:textStyle="bold"/>
<TextView
android:id="@+id/price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/single_padding"
android:layout_marginLeft="@dimen/single_padding"
android:textColor="@color/ascent_color"
android:textSize="@dimen/sku_details_row_text_size"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:layout_marginTop="@dimen/single_padding">
<ImageView
android:id="@+id/sku_icon"
android:gravity="start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/description"
android:layout_marginStart="@dimen/single_padding"
android:layout_marginLeft="@dimen/single_padding"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="@dimen/sku_details_row_description_text_size"
android:layout_weight="1"/>
</LinearLayout>
<Button
android:id="@+id/state_button"
style="@style/ButtonStyle"
android:layout_marginTop="@dimen/single_padding"
android:contentDescription="@string/button_buy"/>
</LinearLayout>
</android.support.v7.widget.CardView>
отображается как:
При запуске приложения запись Sku (заголовок и строка) сворачивается в центр экрана:
, тогда как в примере приложенияy это не так (строка sku занимает весь экран):
Единственное различие с точки зрения компоновки между приложениями - это вид деятельности. Пример представления активности:
TrivialDrivev2 / layout / activity_game.xml:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/loading_indicator"/>
<LinearLayout
android:id="@id/screen_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/title_margin"
android:contentDescription="@string/content_description_title_image"
android:src="@drawable/title"/>
<ImageView
android:id="@id/free_or_premium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/image_margin"
android:contentDescription="@string/content_desc_free_vs_premium_indicator"
android:src="@drawable/free"/>
<ImageView
android:id="@id/gas_gauge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/image_margin"
android:contentDescription="@string/content_desc_gas_gauge_indicator"
android:src="@drawable/gas4"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:id="@id/button_drive"
style="@style/DriveButtonStyle"
android:text="@string/button_drive"/>
<Button
android:id="@id/button_purchase"
style="@style/ButtonStyle"
android:layout_marginTop="@dimen/double_padding"
android:text="@string/button_purchase"/>
</LinearLayout>
</LinearLayout>
</FrameLayout>
и отображается как:
Код, который отображает обе записи sku, одинаков:
AcquireFragment.java:
// If we successfully got SKUs, add a header in front of the row
@StringRes int stringRes = SkuType.INAPP.equals(billingType)
? R.string.header_inapp : R.string.header_subscriptions;
inList.add(new SkuRowData(getString(stringRes)));
// Then fill all the other rows
for (SkuDetails details : skuDetailsList) {
Log.i(TAG, "Adding sku: " + details);
inList.add(new SkuRowData(details, SkusAdapter.TYPE_NORMAL,
billingType));
}
if (inList.size() == 0) {
displayAnErrorIfNeeded();
} else {
if (mRecyclerView.getAdapter() == null) {
mRecyclerView.setAdapter(mAdapter);
Resources res = getContext().getResources();
mRecyclerView.addItemDecoration(new CardsWithHeadersDecoration(
mAdapter, (int) res.getDimension(R.dimen.header_gap),
(int) res.getDimension(R.dimen.row_gap)));
mRecyclerView.setLayoutManager(
new LinearLayoutManager(getContext()));
}
mAdapter.updateData(inList);
setWaitScreen(false);
}
Я подозреваю, что это связаноиз исходного макета, загруженного действием, которое так или иначе затрагивает более поздние фрагменты. Это тот случай? Если да, как я могу переопределить родительский макет из фрагмента получения (чтобы он занимал весь экран)?
Стили:
layout / style / styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="UnityThemeSelector" parent="BaseUnityTheme">
<item name="android:windowBackground">@android:color/black</item>
</style>
<style name="BaseUnityTheme" parent="android:Theme.Light.NoTitleBar.Fullscreen">
</style>
<style name="UnityThemeSelector.Translucent" parent="@style/UnityThemeSelector">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
</style>
<!-- ToolBar -->
<style name="ToolbarStyle" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="titleTextColor">@android:color/white</item>
</style>
<!-- CardView -->
<style name="CardViewStyle" parent="CardView">
<item name="android:layout_marginTop">0dp</item>
<item name="android:layout_marginBottom">0dp</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_marginRight">@dimen/card_view_margin</item>
<item name="android:layout_marginLeft">@dimen/card_view_margin</item>
<item name="cardCornerRadius">@dimen/card_view_card_corner_radius</item>
<item name="cardElevation">@dimen/card_view_card_elevation</item>
<item name="cardPreventCornerOverlap">false</item>
</style>
<attr format="reference" name="cardViewStyle"/>
<color name="cardview_dark_background">#FF424242</color>
<color name="cardview_light_background">#FFFFFFFF</color>
<color name="cardview_shadow_end_color">#03000000</color>
<color name="cardview_shadow_start_color">#37000000</color>
<declare-styleable name="CardView">
<!-- Background color for CardView. -->
<attr format="color" name="cardBackgroundColor"/>
<!-- Corner radius for CardView. -->
<attr format="dimension" name="cardCornerRadius"/>
<!-- Elevation for CardView. -->
<attr format="dimension" name="cardElevation"/>
<!-- Maximum Elevation for CardView. -->
<attr format="dimension" name="cardMaxElevation"/>
<!-- Add padding in API v21+ as well to have the same measurements with previous versions. -->
<attr format="boolean" name="cardUseCompatPadding"/>
<!-- Add padding to CardView on v20 and before to prevent intersections between the Card content and rounded corners. -->
<attr format="boolean" name="cardPreventCornerOverlap"/>
<!-- Inner padding between the edges of the Card and children of the CardView. -->
<attr format="dimension" name="contentPadding"/>
<!-- Inner padding between the left edge of the Card and children of the CardView. -->
<attr format="dimension" name="contentPaddingLeft"/>
<!-- Inner padding between the right edge of the Card and children of the CardView. -->
<attr format="dimension" name="contentPaddingRight"/>
<!-- Inner padding between the top edge of the Card and children of the CardView. -->
<attr format="dimension" name="contentPaddingTop"/>
<!-- Inner padding between the bottom edge of the Card and children of the CardView. -->
<attr format="dimension" name="contentPaddingBottom"/>
<!-- Workaround to read user defined minimum width -->
<attr name="android:minWidth"/>
<!-- Workaround to read user defined minimum height -->
<attr name="android:minHeight"/>
</declare-styleable>
<dimen name="cardview_compat_inset_shadow">1dp</dimen>
<dimen name="cardview_default_elevation">2dp</dimen>
<dimen name="cardview_default_radius">2dp</dimen>
<style name="Base.CardView" parent="android:Widget">
<item name="cardCornerRadius">@dimen/cardview_default_radius</item>
<item name="cardElevation">@dimen/cardview_default_elevation</item>
<item name="cardMaxElevation">@dimen/cardview_default_elevation</item>
<item name="cardUseCompatPadding">false</item>
<item name="cardPreventCornerOverlap">true</item>
</style>
<style name="CardView" parent="Base.CardView">
</style>
<style name="CardView.Dark">
<item name="cardBackgroundColor">@color/cardview_dark_background</item>
</style>
<style name="CardView.Light">
<item name="cardBackgroundColor">@color/cardview_light_background</item>
</style>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="colorAccent">@color/ascent_color</item>
<item name="colorPrimary">@color/primary_color</item>
<item name="colorPrimaryDark">@color/primary_color_dark</item>
</style>
<!-- Button styles -->
<style name="BaseButtonStyle" parent="Widget.AppCompat.Button.Colored">
<item name="android:layout_width">@dimen/button_width</item>
<item name="android:layout_height">@dimen/button_height</item>
</style>
<style name="ButtonStyle" parent="BaseButtonStyle">
<item name="android:background">@color/ascent_color</item>
<item name="android:textColor">@android:color/white</item>
<item name="android:layout_gravity">bottom|end</item>
</style>
<style name="DriveButtonStyle" parent="ButtonStyle">
<item name="android:background">@android:color/white</item>
<item name="android:textColor">@color/ascent_color</item>
</style>
</resources>