0

在我的Android應用程序的活動之一,我有一個ViewFlipper裏面坐了3個ImageViews,建這樣的:ViewFlipper圖像不被視爲

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView 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:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context="com.example.app.MainActivity" 
    tools:showIn="@layout/app_bar_main" 
    android:layout_margin="8dp" 
    android:background="#fff"> 

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

     <ViewFlipper 
      android:id="@+id/flipper" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"> 

      <ImageView 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_gravity="center" 
       android:scaleType="center" 
       android:id="@+id/imageFlipper1" 
       android:adjustViewBounds="true" /> 

      <ImageView 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_gravity="center" 
       android:scaleType="center" 
       android:id="@+id/imageFlipper2" 
       android:adjustViewBounds="true" /> 

      <ImageView 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_gravity="center" 
       android:scaleType="center" 
       android:id="@+id/imageFlipper3" 
       android:adjustViewBounds="true" /> 

     </ViewFlipper> 

    </LinearLayout> 

</ScrollView> 

我從網頁加載圖像使用滑行ImageViews使用此代碼庫(com.github.bumptech.glide:glide:3.7.0'):

flipper = (ViewFlipper) findViewById(R.id.flipper); 
imageFlipper1 = (ImageView) findViewById(R.id.imageFlipper1); 
imageFlipper2 = (ImageView) findViewById(R.id.imageFlipper2); 
imageFlipper3 = (ImageView) findViewById(R.id.imageFlipper3); 

// Load images 
Glide.with(getApplicationContext()).load("url1").into(imageFlipper1); 
Glide.with(getApplicationContext()).load("url2").into(imageFlipper2); 
Glide.with(getApplicationContext()).load("url3").into(imageFlipper3); 

// Setup the ViewFlipper 
flipper.setAutoStart(true); 
flipper.setFlipInterval(2000); 
flipper.startFlipping(); 

的網址是有效的,所以,當我試圖將圖像加載到一個獨立的ImageView,只見屏幕上的圖像。基本上什麼都不應該包含錯誤,但由於某種原因,當我運行應用程序時,屏幕上看不到任何圖像。

你能幫我一下嗎?

回答

0

我終於找到了解決方案。我改變了寬度和ViewFlippermatch_parentwrap_content的高度,內RelativeLayout S的match_parent的寬度和高度,現在我可以看到我的活動圖像:

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView 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:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context="com.example.app.MainActivity" 
    tools:showIn="@layout/app_bar_main" 
    android:layout_margin="8dp" 
    android:background="#fff"> 

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

     <ViewFlipper 
      android:id="@+id/flipper" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

      <RelativeLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_gravity="center" 
       android:gravity="center"> 

       <ImageView 
        android:id="@+id/flipper1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        android:adjustViewBounds="true" 
        android:foregroundGravity="center" 
        android:scaleType="fitCenter"/> 

      </RelativeLayout> 

      <RelativeLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_gravity="center" 
       android:gravity="center"> 

       <ImageView 
        android:id="@+id/flipper2" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        android:adjustViewBounds="true" 
        android:foregroundGravity="center" 
        android:scaleType="fitCenter"/> 

      </RelativeLayout> 

      <RelativeLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_gravity="center" 
       android:gravity="center"> 

       <ImageView 
        android:id="@+id/flipper3" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        android:adjustViewBounds="true" 
        android:foregroundGravity="center" 
        android:scaleType="fitCenter"/> 

      </RelativeLayout> 

     </ViewFlipper> 

    </LinearLayout> 

</ScrollView>