android xml Layout проблема - PullRequest
       14

android xml Layout проблема

0 голосов
/ 25 января 2011

Я уже потратил часы на это, проблема с макетом. Может кто-нибудь сказать мне, как показать и изображение и вид переключателя в одном действии.

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

Если сначала поставить изображение, то при каждой загрузке нового изображения кнопки исчезают, и весь макет кажется перекачанным

Обновление:

В макете должно быть изображение сверху, а затем переключатель вида.

Ответы [ 2 ]

0 голосов
/ 25 января 2011

И небольшой совет, используйте макет, он будет более понятным.

 <include layout="@layout/my_other_layout" />
0 голосов
/ 25 января 2011

Я думаю, что во многом это связано с тем, что вы не можете читать XML. Если это похоже на то, как вы его изначально вставили сюда, то это так. Ваша первая проблема заключается в том, что в вашем корневом теге RelativeLayout ничего не указано, указывающее размер. Корневой макет в большинстве случаев должен быть установлен на layout_width из fill_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".

...