如何在android中的标题上设置图像滑块

问题描述 投票:0回答:3

我是android开发新手请帮帮我。我想在页面顶部设置图像滑块,图像是动态来通过Web服务。图像滑块的示例如下所示:-enter image description here

就像这张图片中的滑块显示(Backstory shop for 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>

目前它显示如下: -

enter image description here

这也给出了一个错误无法在当前主题中找到样式'SliderStyle'是什么意思

android android-layout android-imageview android-image
3个回答
2
投票

不要试图自己制作,而是使用漂亮而简单的库。 qazxsw poi就是其中之一。


2
投票

有很多方法可以达到你想要的效果:1。通过使用View Pager。 2.使用Recycler View(并设置Layout Manager Orientation HORIZONTAL)。

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

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

关键部分是在您附加到这些小部件的适配器中,首先将Urls列表传递给该适配器,然后在其中一个库的帮助下设置Image View Source。


0
投票

使用此库Here

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

在你的活动中

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

https://github.com/MoeidHeidari/banner
© www.soinside.com 2019 - 2024. All rights reserved.