2017-04-16 9 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

ようこそ!これは広すぎて答えが限られており、限られた研究努力しか示されていないので、[良い質問をする](http://stackoverflow.com/help/how-to-ask)を読んでみてください。 – ldz

答えて

0

どこから画像を取得していますか?あなたのDB内の画像か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)); 

addtoList =新しいuploadsclassadapter(この、currentuploads)uploadsclassadapter。

// 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にStackOverflowに

<?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> 
関連する問題