查看鳍状肢不翻转 [英] View flipper is not flipping
问题描述
这甚至可能吗?我创造了这个观点鳍和我打电话从的onClick的XML布局内的视图的鳍状肢。我创建了一个视图的鳍状肢前,但由于某种原因它不工作。
<?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:cacheColorHint =@机器人:彩色/透明
机器人:方向=垂直> < ViewFlipper
机器人:ID =@ + ID / viewFlipper1
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:背景=@空
机器人:cacheColorHint =@机器人:彩色/透明> <的LinearLayout
的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@ + ID / vf_sample1_main
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:cacheColorHint =@机器人:彩色/透明
机器人:方向=垂直> <包括布局=@布局/ headers_main/> <包括布局=@布局/搜索栏/> <的TextView
机器人:ID =@ + ID / sdfsd
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_gravity =CENTER_HORIZONTAL
机器人:重力=CENTER_HORIZONTAL
安卓了maxHeight =85dp
机器人:paddingBottom会=10dp
机器人:paddingTop =10dp
的onClick =gotoSomething
机器人:单线=FALSE/> <的TextView
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:文字颜色=@彩色/ aquablue
机器人:TEXTSIZE =15dp
机器人:文字样式=大胆/> <包括布局=@布局/ listview_item_row_now_playing_info/> <的TextView
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:文字颜色=@彩色/ aquablue
机器人:TEXTSIZE =15dp
机器人:文字样式=大胆/> <包括布局=@布局/ container_listview/>
< / LinearLayout中> <的LinearLayout
的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@ + ID / vf_sdfsdfadf
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:背景=@空
机器人:cacheColorHint =@机器人:彩色/透明
机器人:方向=垂直> <包括布局=@布局/ header_vf_asdfasdfadadafsd/>
< / LinearLayout中> <的LinearLayout
的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@ + ID / vf_adsfasdfadsfasd
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:背景=@空
机器人:cacheColorHint =@机器人:彩色/透明
机器人:方向=垂直>
< / LinearLayout中> < / ViewFlipper>< / LinearLayout中>
code:
公共类BeatSpotPrototypeActivity扩展BaseListActivity {
私人最终字符串标记= BeatSpotPrototypeActivity.class.getSimpleName();
私人ApplicationStateManager mAppStateMananger = ApplicationStateManager.GetInstance();
私人语境mCtx = NULL;
私人布尔mIsInitalized = FALSE;
私人布尔mDataChanded = FALSE;
私人ViewFlipper mViewFlipper = NULL;
私人DrawableManager mDrawManager =新DrawableManager();
私人枚举ViewFlipperModes {
主(0),
NOW_PLAYING(1),
SONG_INFORMATION(2); 私人最终诠释指数; ViewFlipperModes(INT指数){
this.index =指数;
} 公众诠释指数(){
返回指数;
}
}
< / code>
< code>
公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.main_beatspot_activity); 如果(!mIsInitalized)
在里面();
其他
mDataChanded = TRUE;
showLoading(假); } 私人无效的init(){
mCtx =这一点;
mIsInitalized = TRUE;
mViewFlipper =(ViewFlipper)findViewById(R.id.viewFlipper);
fadeDrawables();
}
公共无效gotoBeatspotMain(视图v){
mViewFlipper.setDisplayedChild(ViewFlipperModes.MAIN.index());
} 公共无效gotoNowPlaying(视图v){
Log.d(TAG,mViewFlipper.getCurrentView()的toString());
mViewFlipper.setDisplayedChild(ViewFlipperModes.NOW_PLAYING.index());
} 公共无效gotoSongDetails(视图v){
mViewFlipper.setDisplayedChild(ViewFlipperModes.SONG_INFORMATION.index());
Log.d(TAG,将String.valueOf(ViewFlipperModes.SONG_INFORMATION.index()));
} }
在上创建
ViewFlipper mViewFlipper =(ViewFlipper)findViewbyId(位置);
在你的onCreate(),或在onStart
确保无论你上的setContentView(R.layout.something)布局
确实包含视图的鳍状肢
块引用>也可以尝试这对我来说。此行之前mViewFlipper.setDisplayedChild(ViewFlipperModes.MAIN.index());
式中:INT I =(ViewFlipperModes.MAIN.index());在这里放置一个调试点
mViewFlipper.setDisplayedChild(ⅰ);我也建议使用调试器,试图找出是否你的看法翻转事件被称为内部调试器。
<?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@ + ID / book_as_whole_Layout
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:方向=垂直
机器人:背景=#FFFFFF> < ViewFlipper
机器人:layout_marginTop =20dip
机器人:layout_marginLeft =20dip
机器人:layout_marginRight =20dip
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:ID =@ + ID / ViewFlipper>
<的LinearLayout
机器人:layout_width =match_parent
机器人:layout_height =match_parent> <的TextView
机器人:ID =@ + ID /第1页
机器人:文字=@字符串/ loading_string
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:文字颜色=#000000
机器人:字体=衬/> < / LinearLayout中> <的LinearLayout
机器人:layout_width =match_parent
机器人:layout_height =match_parent>
<的TextView
机器人:ID =@ + ID /第2页
机器人:文字=@字符串/ loading_string
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:文字颜色=#000000
机器人:字体=衬/>
< / LinearLayout中> < / ViewFlipper>
< / LinearLayout中>Is this even possible? I created this view flipper and I am calling the view flipper from the onClick inside of the xml layout. I have created a view flipper before but for some reason it's not working.
<?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>
code:
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())); } }
解决方案before on create
ViewFlipper mViewFlipper = (ViewFlipper)findViewbyId(location);
on your onCreate() or onStart
Ensure that whatever your layout on setcontentView(R.layout.something) does contain the view flipper
Also try this for me. before this line mViewFlipper.setDisplayedChild(ViewFlipperModes.MAIN.index()); Type in:
int i = (ViewFlipperModes.MAIN.index()); place a debug point here mViewFlipper.setDisplayedChild(i);
I also suggest using the debugger to try figure out if your flip views events are being called inside the debugger.
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/book_as_whole_Layout" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="#FFFFFF"> <ViewFlipper android:layout_marginTop="20dip" android:layout_marginLeft="20dip" android:layout_marginRight="20dip" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/ViewFlipper"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/page1" android:text="@string/loading_string" android:layout_width="match_parent" android:layout_height="match_parent" android:textColor="#000000" android:typeface="serif"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/page2" android:text="@string/loading_string" android:layout_width="match_parent" android:layout_height="match_parent" android:textColor="#000000" android:typeface="serif" /> </LinearLayout> </ViewFlipper> </LinearLayout>
这篇关于查看鳍状肢不翻转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!