2010-11-16 2 views
2

Я пытаюсь создать очень простой экран для Android со следующим содержанием: верхний баннер, веб-представление и нижний баннер. по какой-то причине я не могу этого сделать. мой xml выглядит так:Экран с верхним баннером, webview и нижним баннером

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout android:id="@+id/FrameLayout02" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:fitsSystemWindows="true" android:isScrollContainer="false"> 


    <ImageView android:layout_width="wrap_content" android:layout_above="@+id/Web" 
     android:layout_height="fill_parent" android:layout_gravity="top" 
     android:src="@drawable/logo"></ImageView> 


    <WebView android:layout_gravity="center" android:id="@+id/Web" 
     android:layout_height="fill_parent" android:layout_width="fill_parent"></WebView> 

    <ImageView android:layout_width="wrap_content" android:layout_below="@+id/Web" 
     android:layout_height="fill_parent" android:layout_gravity="bottom" 
     android:src="@drawable/logo"></ImageView> 

</LinearLayout> 

что не так?

Спасибо, Daniel

ответ

9

Короткий ответ все это неправильно. Ваш код беспорядок.

Длинный ответ. Вы пытаетесь иметь ImageView выше WebView и внизу ImageView. Я не совсем уверен, что из-за ошибок сломал, но это тоже не важно. Взгляните на мой пример кода XML.

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <ImageView android:id="@+id/topimage" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:src="@drawable/icon"/> 
    <ImageView android:id="@+id/bottomimage" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:src="@drawable/icon"/> 
    <WebView android:id="@+id/web" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/topimage" 
     android:layout_above="@id/bottomimage"/> 
</RelativeLayout> 

Теперь мой XML-код прост. Он использует RelativeLayout в качестве контейнера, чтобы обеспечить более гибкое выравнивание потомков. ImageView под названием topimage отрегулирует его высоту до ее содержимого и заполнит родительский шрифт по ширине. Он ориентирован на родителей. Второй ImageView похож с единственным исключением, что он прикреплен к его родителям внизу. WebView выровнен между ImageView. Он настраивает высоту на высоту ImageView.

Постарайтесь всегда сохранять какую-то структуру в своем XML-коде, а также код Java, чтобы вы, а также другие могли взглянуть на него, не задумываясь.

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