I already spent hours on this, its a layout issue. can someone tell me how to show both image and view switcher in the same activity.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res/rg.client.muscle"
android:layout_width="fill_parent"
android:layout_height="fil_parent">
<ViewSwitcher
android:id="@+id/relative"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<!-- contains two relative layouts of same sizes
containing same elements just with switched positions -->
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<com.admob.android.ads.AdView
android:id="@+id/adv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
myapp:backgroundColor="#000000"
myapp:primaryTextColor="#FFFFFF"
myapp:secondaryTextColor="#CCCCCC"
myapp:refreshInterval="30" >
</com.admob.android.ads.AdView>
<LinearLayout
android:id="@+id/linear"
android:orientation="horizontal"
android:weightSum="100"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@id/adv" >
<Button
android:id="@+id/but_prev2"
android:text="Previous"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="30" >
</Button>
开发者_StackOverflow中文版 <Button
android:id="@+id/but_more2"
android:text="More"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="40" >
</Button>
<Button
android:id="@+id/but_next2"
android:text="Next"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="30">
</Button>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<LinearLayout
android:id="@+id/linear2"
android:orientation="horizontal"
android:weightSum="100"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<Button
android:id="@+id/but_prev"
android:text="Previous"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="30">
</Button>
<Button
android:id="@+id/but_more"
android:text="More"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="40">
</Button>
<Button
android:id="@+id/but_next"
android:text="Next"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="30">
</Button>
</LinearLayout>
<com.admob.android.ads.AdView
android:id="@+id/adv2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@id/linear2"
myapp:backgroundColor="#000000"
myapp:primaryTextColor="#FFFFFF"
myapp:secondaryTextColor="#CCCCCC"
myapp:refreshInterval="30">
</com.admob.android.ads.AdView>
</RelativeLayout>
</ViewSwitcher>
<ImageView
android:id="@+id/image"
android:layout_above="@id/relative"
android:padding="2pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" >
</ImageView>
</RelativeLayout>
If I put the imageview first then each time a new image is loaded the buttons disappear and the whole layout seems to be re inflated
Update:
The layout must have an image view at the top then a view switcher.
I imagine a lot of it has to do with you not being able to read your XML. If it looks anything like the way you originally pasted it in here, that is. Your first problem is that you have nothing in your root RelativeLayout tag specifying a size. Your root layout should be in most cases set to a layout_width
of fill_parent
, same with the layout_height
. You also need your schema specification (i.e. xmlns:android="http://schemas.android.com/apk/res/android"
although I'm assuming you just left that out, since you're actually getting it to compile.
You also may want to keep in mind, since most everything is set to wrap_content
for height, if it ever exceeds the height of the screen, some of it will not be visible, so you may consider wrapping the inner portion into a ScrollView
.
EDIT: Again, I'd suggest setting your RelativeLayout (root element) to have a height of fill_parent
. Try defining your ImageView first, leaving it with alignParentTop="true"
, then define your ViewSwitcher, and give it the layout_below="@id/image"
attribute.
And small advice, use include layout, it will be more clear.
<include layout="@layout/my_other_layout" />
精彩评论