【问题标题】:How to set image slider on header in android如何在android中的标题上设置图像滑块
【发布时间】:2015-10-06 06:56:27
【问题描述】:

我是android开发新手,请帮助我。 我想在页面顶部设置图像滑块,并且图像是通过网络服务动态获得的。图像滑块示例如下:-

就像这张图片中的滑块显示(Back Story shop fro Backpacks)一样,我也想要并记住图片是动态的。

我的activity.main.xml:

<RelativeLayout xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:custom="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
    android:id="@+id/linear_layout_outer"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <include
        android:id="@+id/toolbar"
        layout="@layout/toolbar" />
    </LinearLayout>

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:layout_below="@+id/linear_layout_outer">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <com.daimajia.slider.library.SliderLayout
            android:id="@+id/slider"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            custom:pager_animation="Accordion"
            custom:auto_cycle="true"
            custom:indicator_visibility="visible"
            custom:pager_animation_span="1100" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <HorizontalScrollView
                android:id="@+id/linear_layout_special_product_horizontal_scroll_view"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:scrollbars="none">

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">

                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal">

                        <ImageView
                            android:id="@+id/linear_layout_special_produce_image01"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:src="@drawable/shop240x320"
                            android:paddingRight="65dp"
                            android:contentDescription="@string/special_producr"/>

                        <ImageView
                            android:id="@+id/linear_layout_special_produce_image02"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:src="@drawable/shop240x320"
                            android:paddingRight="65dp"
                            android:contentDescription="@string/special_producr"/>

                        <ImageView
                            android:id="@+id/linear_layout_special_produce_image03"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:src="@drawable/shop240x320"
                            android:paddingRight="65dp"
                            android:contentDescription="@string/special_producr"/>

                        <ImageView
                            android:id="@+id/linear_layout_special_produce_image04"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:src="@drawable/shop240x320"
                            android:paddingRight="65dp"
                            android:contentDescription="@string/special_producr"/>

                        <ImageView
                            android:id="@+id/linear_layout_special_produce_image05"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:src="@drawable/shop240x320"
                            android:paddingRight="65dp"
                            android:contentDescription="@string/special_producr"/>
                    </LinearLayout>
                </LinearLayout>
            </HorizontalScrollView>
        </LinearLayout>  
    </LinearLayout>
</ScrollView></RelativeLayout>

目前显示如下:-

这也给出了一个错误 Failed to find style 'SliderStyle' in current theme 是什么意思

【问题讨论】:

  • 使用ViewPager 与下方的布局...
  • 我尝试了,但我无法在视图寻呼机中设置图像动态
  • ViewPager with PagerAdapter 或 FragmentPagerAdapter 是你应该研究的。
  • 这可以通过带有页面指示器的viewpager来实现(对于下面的点)。您需要发布代码以获得更好的解释。

标签: android android-layout android-imageview android-image


【解决方案1】:

与其尝试自己制作,不如使用漂亮而简单的库。 Here 就是其中之一。

【讨论】:

    【解决方案2】:

    有很多方法可以实现您想要的: 1. 通过使用 View Pager。 2.使用Recycler View(并设置Layout Manager Orientation HORIZONTAL)。

    以上两个是用于以上述设计格式呈现图像视图(或其他视图)的最简单和基本的小部件。

    现在您还需要做一件事:在这些图像视图中呈现您的实际图像。 我假设您正在从某些 Web 服务中获取 Url 的列表。现在您需要将这些 url 渲染到您的 ImageView 中。为此,您可以使用 3rd 方库,例如 picaso 或 Aquery。

    关键部分是在您附加到这些小部件的适配器中,首先将 URL 列表传递给该适配器,然后借助这些库之一设置图像视图源。

    【讨论】:

      【解决方案3】:

      使用这个库 https://github.com/MoeidHeidari/banner

      实现'com.github.MoeidHeidari:banner:1.04'

      在你的活动中

      BannerLayout banner=(BannerLayout) findViewById(R.id.Banner);

          List<String> urls = new ArrayList<>();
          urls.add("http://szzljy.com/images/mountain/mountain4.jpg");
          urls.add("http://szzljy.com/images/mountain/mountain4.jpg");
          urls.add("http://www.visitgreece.gr/deployedFiles/StaticFiles/Photos/Generic%20Contents/Forests/mountains_2_560.jpg");
          urls.add("http://szzljy.com/images/mountain/mountain4.jpg");
          urls.add("http://www.visitgreece.gr/deployedFiles/StaticFiles/Photos/Generic%20Contents/Forests/mountains_2_560.jpg");
          urls.add("http://szzljy.com/images/mountain/mountain4.jpg");
      
      
          BaseBannerAdapter webBannerAdapter=new BaseBannerAdapter(this,urls);
          webBannerAdapter.setOnBannerItemClickListener(new BannerLayout.OnBannerItemClickListener() {
              @Override
              public void onItemClick(int position)
              {
      
      
              }
          });
          banner.setAdapter(webBannerAdapter);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-02-17
        • 1970-01-01
        • 2019-08-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多