【问题标题】:How can i add multiple images inside my collapsible toolbar? [closed]如何在可折叠工具栏中添加多个图像? [关闭]
【发布时间】:2017-08-16 04:21:21
【问题描述】:

如何在可折叠工具栏中添加许多图像?我基本上想在可折叠工具栏中显示图像幻灯片。

在下面给出的图像中,灰色区域实际上位于可折叠工具栏内,它表示图像加载器(我称之为幻灯片)。现在,当用户向上滚动时,我希望那个灰色框随着折叠工具栏本身消失。那么我如何使该灰色区域包含图像作为幻灯片显示

【问题讨论】:

  • 看看这个solution
  • @knightcube 您尝试过以下解决方案吗?

标签: android xml material-design


【解决方案1】:

这是一个建议。您可以找到Android Image Slider 库。

创建布局结构:

<?xml version="1.0" encoding="utf-8"?>
<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:id="@+id/spiceCoordinatorLayoutId"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:fitsSystemWindows="true">

  <android.support.design.widget.AppBarLayout
    android:id="@+id/appBarLayoutId"
    android:layout_width="match_parent"
    android:layout_height="290dp"
    android:fitsSystemWindows="true">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsingToolbarId"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:contentScrim="@color/colorNavigationBarHeaderColor"
        app:expandedTitleMarginEnd="64dp"
        app:expandedTitleMarginStart="48dp"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        app:statusBarScrim="@color/colorAreaStatusBarColor"
        app:titleEnabled="false">

        <com.daimajia.slider.library.SliderLayout
            android:id="@+id/slider"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:layout_collapseMode="parallax" />

        <android.support.v7.widget.Toolbar
            android:id="@+id/spiceToolbarId"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_collapseMode="pin"
            app:navigationIcon="?attr/homeAsUpIndicator">

        </android.support.v7.widget.Toolbar>

    </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"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <LinearLayout
        android:id="@+id/llSpiceDetailContainer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="15dp"
        android:orientation="vertical">

       // some content           

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

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

此代码来自Android Image Slider 库的演示活动MainActiivty

https://github.com/daimajia/AndroidImageSlider/blob/master/demo/src/main/java/com/daimajia/slider/demo/MainActivity.java

private SliderLayout mDemoSlider;

mDemoSlider = (SliderLayout)findViewById(R.id.slider);

    HashMap<String,String> url_maps = new HashMap<String, String>();
    url_maps.put("Hannibal", "http://static2.hypable.com/wp-content/uploads/2013/12/hannibal-season-2-release-date.jpg");
    url_maps.put("Big Bang Theory", "http://tvfiles.alphacoders.com/100/hdclearart-10.png");
    url_maps.put("House of Cards", "http://cdn3.nflximg.net/images/3093/2043093.jpg");
    url_maps.put("Game of Thrones", "http://images.boomsbeat.com/data/images/full/19640/game-of-thrones-season-4-jpg.jpg");

    HashMap<String,Integer> file_maps = new HashMap<String, Integer>();
    file_maps.put("Hannibal",R.drawable.hannibal);
    file_maps.put("Big Bang Theory",R.drawable.bigbang);
    file_maps.put("House of Cards",R.drawable.house);
    file_maps.put("Game of Thrones", R.drawable.game_of_thrones);

    for(String name : file_maps.keySet()){
        TextSliderView textSliderView = new TextSliderView(this);
        // initialize a SliderLayout
        textSliderView
                .description(name)
                .image(file_maps.get(name))
                .setScaleType(BaseSliderView.ScaleType.Fit)
                .setOnSliderClickListener(this);

        //add your extra information
        textSliderView.bundle(new Bundle());
        textSliderView.getBundle()
                    .putString("extra",name);

       mDemoSlider.addSlider(textSliderView);
    }

【讨论】:

  • 喜欢这个解决方案:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-07-22
  • 2016-04-20
  • 1970-01-01
  • 2016-10-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多