2017-04-16 45 views
-3

我試圖在視圖鰭狀肢中隨機顯示佈局(我有4個佈局 - 他們會更多)。這是我迄今爲止如何使viewflipper中的佈局隨機

public class MainActivity extends AppCompatActivity { 

Random mRandom = new Random(); 



@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    ViewFlipper simpleViewFlipper = (ViewFlipper) findViewById(R.id.simpleViewFlipper); 

    Animation in = AnimationUtils.loadAnimation(this, android.R.anim.fade_in); 
    Animation out = AnimationUtils.loadAnimation(this, android.R.anim.fade_out); 

    simpleViewFlipper.setInAnimation(in); 
    simpleViewFlipper.setOutAnimation(out); 

    simpleViewFlipper.setFlipInterval(3000); 
    simpleViewFlipper.setAutoStart(true); 

    simpleViewFlipper.setDisplayedChild(mRandom.nextInt(4)); 

} 

}

我希望他們隨機顯示,永不止步。

請裸記住,我是一個初學者:)

感謝。

+0

歡迎的StackOverflow!您可能需要閱讀[提出良好問題](http://stackoverflow.com/help/how-to-ask),因爲這篇文章太寬泛無法回答,僅顯示有限的研究成果。 – ldz

回答

0

你從哪裏得到你的圖片?數據庫中的圖像還是隻存在於SRC文件夾中?任何嘗試編碼?給我們更多的信息。

例如...

setContentView(R.layout.yourxml); 
    ArrayList<uploadsclass> currentuploads = new ArrayList<uploadsclass>(); 
      currentuploads.add(new uploadsclass("MYBRAND NEW AUDI", "1.6TDI, 220 CCM, diesel", R.drawable.audi)); 

uploadsclassadapter addtoList =新uploadsclassadapter(此,currentuploads);

// Get a reference to the ListView, and attach the adapter to the listView. 
    ListView listView = (ListView) findViewById(R.id.listview_ids); 
    listView.setAdapter(addtoList); 

yourxml.xml:

<ListView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/listview_ids" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" /> 

您listitems.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center_vertical" 
    android:orientation="horizontal" 
    android:minHeight="?android:attr/listPreferredItemHeight"> 

    <ImageView 
     android:id="@+id/oneCarImage" 
     android:layout_width="50dp" 
     android:layout_height="64dp" 
     android:layout_weight="0.04" /> 

    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:orientation="vertical" 
     android:paddingLeft="16dp"> 

     <TextView 
      android:id="@+id/quickInfo" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"/> 

     <TextView 
      android:id="@+id/quickCharacteristics" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

    </LinearLayout> 

</LinearLayout>