0

私はすでにこれに何時間も費やしました、それはレイアウトの問題です。同じアクティビティで画像とビュースイッチャーの両方を表示する方法を教えてもらえますか?

<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を最初に配置すると、新しい画像が読み込まれるたびにボタンが消え、レイアウト全体が再び膨らんだように見えます

アップデート:

レイアウトの上部には画像ビューがあり、次にビュースイッチャーが必要です。

4

2 に答える 2

0

それの多くは、XMLを読み取れないことに関係していると思います。ここに最初に貼り付けた方法と同じように見える場合は、それです。最初の問題は、ルートのRelativeLayoutタグにサイズを指定するものが何もないことです。ルートレイアウトは、ほとんどの場合、と同じlayout_widthのに設定する必要があります。スキーマ仕様も必要です(つまり、実際にコンパイルするため、スキーマ仕様は省略したと思いますが。fill_parentlayout_heightxmlns:android="http://schemas.android.com/apk/res/android"

また、ほとんどすべてが高さに設定されているwrap_contentため、画面の高さを超えると一部が表示されなくなるため、内側をで囲むことを検討してくださいScrollView

編集:繰り返しますが、RelativeLayout(ルート要素)の高さを。に設定することをお勧めしますfill_parent。最初にImageViewを定義し、を残してからalignParentTop="true"、ViewSwitcherを定義し、layout_below="@id/image"属性を指定してみてください。

于 2011-01-25T16:54:10.590 に答える
0

そして、小さなアドバイス、レイアウトを含む使用、それはより明確になります。

 <include layout="@layout/my_other_layout" />
于 2011-01-25T17:34:06.137 に答える