我有1個viewflipper,它包含3個佈局。佈局1有兩個按鈕來顯示下一個,另一個去另一個活動。第二個佈局有3個按鈕。我想要的是知道如何控制第二個佈局,並在每個按鈕上點擊播放器,以便我可以製作一個用於下一個節目,另一個用於另一個節目。Android ViewFlipper更多控制
這是XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
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"
tools:context=".MainActivity" >
<ViewFlipper
android:id="@+id/viewFlipper1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="44dp"
android:src="@drawable/ballchr3" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/imageView1"
android:layout_toLeftOf="@+id/imageView3"
android:src="@drawable/ballchr4" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="73dp"
android:layout_toRightOf="@+id/imageView3"
android:src="@drawable/ballchr3" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/imageView1"
android:layout_toLeftOf="@+id/imageView3"
android:src="@drawable/ballchr4" />
<ImageView
android:id="@+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="128dp"
android:src="@drawable/ballchr5" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignRight="@+id/imageView2"
android:layout_marginTop="76dp"
android:src="@drawable/ballchr3" />
</RelativeLayout>
</ViewFlipper>
</RelativeLayout>
活動代碼
public class MainActivity extends Activity implements OnClickListener {
ViewFlipper viewflipper;
ImageView btn, fail;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
viewflipper = (ViewFlipper)findViewById(R.id.viewFlipper1);
btn = (ImageView)findViewById(R.id.imageView1);
fail = (ImageView)findViewById(R.id.imageView2);
btn.setOnClickListener(this);
fail.setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
switch(arg0.getId()){
case R.id.imageView1:
viewflipper.showNext();
break;
case R.id.imageView2:
Intent i = new Intent(MainActivity.this, Fail.class);
startActivity(i);
break;
}
}
我真的不明白是什麼問題? – Aeefire 2013-02-18 09:14:46