2011-01-25 4 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 первого тот каждый раз, когда новое изображение загружается кнопка исчезает, и весь макет, кажется, вновь надувается

Update:

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

ответ

0

Я предполагаю, что многое из этого связано с тем, что вы не можете читать свой XML. Если это похоже на то, как вы вначале вставляли его здесь, то есть. Ваша первая проблема заключается в том, что у вас нет ничего в вашем корневом элементе RelativeLayout, определяющем размер. Корневая компоновка должна быть в большинстве случаев установлена ​​на layout_widthfill_parent, то же самое с layout_height. Вам также нужна ваша спецификация схемы (т. Е. xmlns:android="http://schemas.android.com/apk/res/android", хотя я предполагаю, что вы просто ее оставили, так как вы на самом деле ее собираете.

Вы также можете иметь в виду, так как большинство всего установлено на wrap_content для высоты, если она когда-либо превышает высоту экрана, некоторые из них не будут видны, поэтому вы можете рассмотреть возможность обертывания внутренней части в ScrollView.

EDIT: Опять же, я предлагаю установить RelativeLayout (корень элемент), чтобы иметь высоту fill_parent. Сначала попробуйте определить свой ImageView, оставив его с alignParentTop="true", затем определите свой ViewSwitcher и дайте ему атрибут layout_below="@id/image".

+0

Извините, я просто не добавил то, что вы говорите здесь. Но все они настроены в коде. – JehandadK

+0

Возможно, вам следует добавить их, если вы хотите получить точный ответ. Попробуйте добавить 'android: layout_below =" @ id/image "' в ваш ViewSwitcher. Не зная макет и содержание внутри, трудно сказать. Кроме того, RelativeLayouts не имеет атрибута 'android: orientation', а только LinearLayout. Использование этих функций не влияет на RelativeLayout. – kcoppock

+0

исправлено и добавлено место, где должно быть изображение. – JehandadK

0

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

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

Я хочу следовать этому, на данный момент у меня проблемы с событиями и всеми. Если я вставляю те же макеты, используя include, как я могу получить идентификатор кнопок. – JehandadK

Смежные вопросы