2015-10-06 89 views
-1

我在新开发Android,请帮助我。 我想在页面顶部设置图像滑块,并通过Web服务动态显示图像。图像滑块的例子如下: - enter image description here如何设置页眉图片滑块的Android

就像这个图像中的滑块显示(Back Story shop来回背包)同样我也想要和记住图像是动态的。

我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' 在当前主题是什么意思

+1

使用'ViewPager'与布局在... – Mohit

+0

我尝试,但我不能设置图像动态查看寻呼机 –

+1

ViewPager与PagerAdapter或FragmentPagerAdapter是你应该看看。 –

回答

1

相反特林使它自己,都使用了简单好用的库。 Here就是其中之一。

+0

Thnaks @Amir它的工作很好 –

1

有很多的方式来实现你想要喜欢什么: 1.通过使用视图寻呼机。 2.使用Recycler View(并设置布局管理器方向HORIZONTAL)。

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

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

的关键部分是在你的适配器,它要连接到这些部件,第一URL列表传递给适配器,然后设置图像查看源文件使用这些库之一的帮助。