Android RealViewSwticher problem
Many of you know, that there's is a class RealViewSwticher created by Marc Reichelt http://marcreichelt.blogspot.com/2010_09_01_archive.html
If someone used or uses this thing, please can you help me.
开发者_如何学编程Here's my .xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<de.marcreichelt.android.RealViewSwitcher
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/real_view_switcher">
<GridView android:id="@+id/gridView1" android:layout_width="match_parent" android:layout_height="match_parent"></GridView>
<GridView android:id="@+id/gridView2" android:layout_width="match_parent" android:layout_height="match_parent"></GridView>
</de.marcreichelt.android.RealViewSwitcher>
</LinearLayout>
And here's my main class.
public class MyMain extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
RealViewSwitcher realViewSwitcher = (RealViewSwitcher)findViewById(R.id.real_view_switcher);
GridView gridview = (GridView) findViewById(R.id.gridView1);
GridView gridview2 = (GridView) findViewById(R.id.gridView2);
gridview.setAdapter(new ImageAdapter(this));
gridview2.setAdapter(new ImageAdapter(this));
realViewSwitcher.setOnScreenSwitchListener(onScreenSwitchListener);
}
private final RealViewSwitcher.OnScreenSwitchListener onScreenSwitchListener = new RealViewSwitcher.OnScreenSwitchListener() {
@Override
public void onScreenSwitched(int screen) {
// this method is executed if a screen has been activated, i.e. the screen is completely visible
// and the animation has stopped (might be useful for removing / adding new views)
Log.d("RealViewSwitcher", "switched to screen: " + screen);
}
};
}
I really don't understand what i am doing wrong, in the Example there's comment how to use it in xml:
// note that you can also define your own views directly in a resource XML, too by using:
// <de.marcreichelt.android.RealViewSwitcher
// android:layout_width="fill_parent"
// android:layout_height="fill_parent"
// android:id="@+id/real_view_switcher">
// <!-- your views here -->
// </de.marcreichelt.android.RealViewSwitcher>
The problem is: It is not working. I can see only my main GridView and i can't scroll to the second. If soemeone knews how where i made a mistake or if someone knews another way to do a real scrolling between views, please answer this.
why don't you use ScrollView? Try to use something like this:
<ScrollView android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="110px">
<LinearLayout
android:id="@+id/grds"
android:drawingCacheQuality="low"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<GridView android:id="@+id/gridView1" android:layout_width="match_parent" android:layout_height="match_parent"></GridView>
<GridView android:id="@+id/gridView2" android:layout_width="match_parent" android:layout_height="match_parent"></GridView>
</LinearLayout>
</ScrollView>
if it does't work, looak at this post
Switching between two GridViews in the same Activity
精彩评论