2015-10-06 22 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列表傳遞給適配器,然後設置圖像查看源文件使用這些庫之一的幫助。