1

最近、既存のアプリケーションにマテリアル デザインを実装しています。このために、次のライブラリを使用しています: http://android-developers.blogspot.com/2015/05/android-design-support-library.html次の効果を達成するため: https://plus.google.com/ +AndroidDevelopers/posts/XUDGFS9eYxg .

私のレイアウトコードは以下のようなものです:

<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">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="350dp"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginBottom="32dp"
            app:expandedTitleMarginEnd="64dp"
            app:expandedTitleMarginStart="48dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <ImageView
                android:id="@+id/event_image"
                android:layout_width="fill_parent"
                android:layout_height="350dp"
                android:background="@color/white"
                android:fitsSystemWindows="true"
                android:scaleType="centerCrop"
                app:layout_collapseMode="parallax" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/anim_toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.NestedScrollView

--------

   </android.support.v4.widget.NestedScrollView>

    <android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="30dp"
        android:clickable="true"
        android:src="@drawable/ic_action_share"
        app:layout_anchor="@+id/appbar"
        app:layout_anchorGravity="bottom|right|end" />

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

目的の効果が得られますが、画像とテキストに問題があります。テキストは白色ですが、画像の大部分が白色である場合、テキスト ラベルが読み取れません。

効果を破壊せずに解決する方法はありますか?

4

4 に答える 4

2

ヒントをくれた @m vai に感謝し、別のアプローチを使用しました。を作成しFrameLayout、内部にImageViewGradientView を配置します。次に、すべてのアニメーション属性を FrameLayout に渡しました。最後はとてもシンプルでした。したがって、代わりにImageView次のコードを使用する必要があります。

  <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layout_collapseMode="parallax"
                android:fitsSystemWindows="true">

                <RelativeLayout
                    android:id="@+id/title_layout"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content">

                    <ImageView
                        android:id="@+id/event_image"
                        android:layout_width="fill_parent"
                        android:layout_height="350dp"
                        android:background="@color/white"
                        android:scaleType="centerCrop"
                       />

                </RelativeLayout>

                <View
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@drawable/actionbar_overlay" />
            </FrameLayout>

XML ファイルは次のようになります。

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle">

    <size android:height="100dp"/>

    <gradient
        android:angle="270"
        android:startColor="#0000"
        android:endColor="#b000"/>

</shape>
于 2015-06-26T13:04:17.183 に答える
1

これは、テキストに影を付けることでも解決できます。

たとえば、このスタイル例を TextView に適用すると、白い画像に白いテキストが表示されていても完全に表示されます。

<style name="ShadowTextStyle" parent="@android:style/TextAppearance">
    <item name="android:textSize">35sp</item>
    <item name="android:textStyle">bold</item>
    <item name="android:textColor">@color/White</item>
    <item name="android:layout_marginLeft">40dp</item>
    <item name="android:layout_marginBottom">10dp</item>
    <item name="android:shadowColor">@android:color/black</item>
    <item name="android:shadowDx">0</item>
    <item name="android:shadowDy">0</item>
    <item name="android:shadowRadius">25</item>
</style>

結果:

ここに画像の説明を入力

于 2015-12-07T15:47:32.327 に答える
0

以下のソリューションも適用できます。

  <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_collapseMode="parallax"
        android:fitsSystemWindows="true">

        <RelativeLayout
            android:id="@+id/title_layout"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">

            <ImageView
                android:id="@+id/ivRestaurantImage"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/gradient"
                android:scaleType="fitXY"
                android:src="@drawable/second_img" />

        </RelativeLayout>

        <View
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/gradient" />
    </FrameLayout>

勾配.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<gradient
    android:angle="90"
    android:startColor="#00ffffff"
    android:endColor="#aa000000"
   />
</shape>
于 2018-11-03T07:06:05.900 に答える