这甚至可能吗?我创建了这个视图翻转器,我从 xml 布局内部的 onClick 调用视图翻转器。我之前创建了一个视图翻转器,但由于某种原因它不起作用。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:cacheColorHint="@android:color/transparent"
android:orientation="vertical" >
<ViewFlipper
android:id="@+id/viewFlipper1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@null"
android:cacheColorHint="@android:color/transparent" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/vf_sample1_main"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:cacheColorHint="@android:color/transparent"
android:orientation="vertical" >
<include layout="@layout/headers_main" />
<include layout="@layout/searchbar" />
<TextView
android:id="@+id/sdfsd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:maxHeight="85dp"
android:paddingBottom="10dp"
android:paddingTop="10dp"
onClick="gotoSomething"
android:singleLine="false" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/aquablue"
android:textSize="15dp"
android:textStyle="bold" />
<include layout="@layout/listview_item_row_now_playing_info" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/aquablue"
android:textSize="15dp"
android:textStyle="bold" />
<include layout="@layout/container_listview" />
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/vf_sdfsdfadf"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@null"
android:cacheColorHint="@android:color/transparent"
android:orientation="vertical" >
<include layout="@layout/header_vf_asdfasdfadadafsd" />
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/vf_adsfasdfadsfasd"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@null"
android:cacheColorHint="@android:color/transparent"
android:orientation="vertical" >
</LinearLayout>
</ViewFlipper>
</LinearLayout>
代码:
public class BeatSpotPrototypeActivity extends BaseListActivity {
private final String TAG = BeatSpotPrototypeActivity.class.getSimpleName();
private ApplicationStateManager mAppStateMananger = ApplicationStateManager.GetInstance();
private Context mCtx = null;
private boolean mIsInitalized = false;
private boolean mDataChanded= false;
private ViewFlipper mViewFlipper= null;
private DrawableManager mDrawManager = new DrawableManager();
private enum ViewFlipperModes {
MAIN (0),
NOW_PLAYING (1),
SONG_INFORMATION (2);
private final int index;
ViewFlipperModes(int index) {
this.index = index;
}
public int index() {
return index;
}
}
</code>
<code>
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_beatspot_activity);
if (!mIsInitalized)
init();
else
mDataChanded = true;
showLoading(false);
}
private void init() {
mCtx = this;
mIsInitalized = true;
mViewFlipper = (ViewFlipper)findViewById(R.id.viewFlipper);
fadeDrawables();
}
public void gotoBeatspotMain(View v) {
mViewFlipper.setDisplayedChild(ViewFlipperModes.MAIN.index());
}
public void gotoNowPlaying(View v) {
Log.d(TAG, mViewFlipper.getCurrentView().toString());
mViewFlipper.setDisplayedChild(ViewFlipperModes.NOW_PLAYING.index());
}
public void gotoSongDetails(View v) {
mViewFlipper.setDisplayedChild(ViewFlipperModes.SONG_INFORMATION.index());
Log.d(TAG, String.valueOf(ViewFlipperModes.SONG_INFORMATION.index()));
}
}