我正试图在视图鳍状肢中随机显示布局(我有4个布局 - 它们会更多)。这就是我到目前为止所拥有的
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 :(得分: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 = new uploadsclassadapter(this,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>