2011-01-25 11 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_parentlayout_heightと同じに設定する必要があります。

ほとんどのものはwrap_contentに設定されていますので、お使いのスキーマの仕様(つまり、xmlns:android="http://schemas.android.com/apk/res/android"も必要です)を残しておきます。高さの場合、画面の高さを超えると表示されないので、内側の部分をScrollViewにラップすることを検討してください。

EDIT:もう一度、RelativeLayout要素)の高さをfill_parentに設定してください。ImageViewを最初に定義し、alignParentTop="true"のままにしてから、ViewSwitcherを定義し、layout_below="@id/image"という属性を与えてください。

+0

私は申し訳ありませんが、ここであなたが言っていることを追加しませんでした。しかし、それらはすべてコード内に設定されています。 – JehandadK

+0

正確な回答が必要な場合は、おそらくそれらを追加してください。 ViewSwitcherに 'android:layout_below =" @ id/image "'を追加してみてください。あなたのレイアウトとその中の内容を知らなくても、言うことは難しいです。また、RelativeLayoutsには 'android:orientation'属性がありません。ちょうどLinearLayoutです。これらを使用すると、RelativeLayoutには何の効果もありません。 – kcoppock

+0

を修正し、画像が必要な部分も追加しました。 – JehandadK

0

小さなアドバイス、使用レイアウトを使用すると、より明確になります。

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

私はそれに従いたいと思っています。今、私はイベントやすべてを扱うのに困っています。もしincludeを使って同じレイアウトに入れたら、どのようにボタンのidを得ることができますか? – JehandadK

関連する問題