2011-01-25 60 views
0

我已经花了几个小时,这是一个布局问题。有人能告诉我如何在同一活动中显示图像和视图切换器。android xml布局问题

<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> 

       <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> 

如果我第一次每一个新的形象被载入按钮消失,整个布局似乎要重新充气时间把ImageView的那么

更新:

布局必须有一个形象图在顶部,然后是视图切换器。

回答

0

我想它有很多与你无法读取你的XML有关。如果它看起来像你最初在这里粘贴的方式,那就是。你的第一个问题是,你的根的RelativeLayout标签中没有指定大小的东西。在大多数情况下,您的根布局应设置为layout_widthfill_parent,与layout_height相同。您还需要您的架构规范(例如xmlns:android="http://schemas.android.com/apk/res/android",尽管我假设您只是将它遗留下来,因为您实际上正在编译它)。

您也可能想记住,因为大多数情况都设置为wrap_content对于高度,如果它曾经超过屏幕的高度,其中一些将不可见,所以你可以考虑将内部包裹成ScrollView

编辑:再次,我会建议设置你的RelativeLayout(根元素)的高度为fill_parent,先试着定义你的ImageView,留下alignParentTop="true",然后定义你的ViewSwitcher,并给它layout_below="@id/image"属性。

+0

对不起,我只是没有添加你在这里说的东西。但他们都在代码中设置。 – JehandadK 2011-01-25 16:58:43

+0

如果你想要一个准确的答案,你应该添加它们。尝试在您的ViewSwitcher中添加`android:layout_below =“@ id/image”`。不知道你的布局和内容,很难说。另外,RelativeLayouts没有`android:orientation`属性,只有LinearLayout。使用这些对RelativeLayout没有影响。 – kcoppock 2011-01-25 17:02:55

0

和小的建议,使用包括布局,它会更清楚。

<include layout="@layout/my_other_layout" />