屏幕与*横幅,webview和底部横幅
问题描述:
我想创建一个非常简单的android屏幕,具有以下内容:顶部横幅,webview和底部横幅。出于某种原因,我不能这样做。我的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>
有什么不对?
感谢, 丹尼尔
答
简短的回答全部是错误的。你的代码乱七八糟。
长的答案。您正试图在WebView
以上的ImageView
以及另一个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
作为容器以允许更灵活的子对齐。调用topimage
的ImageView
将调整其高度至其内容并填充父宽度。它与其父母一致。第二个ImageView
是唯一的例外,它被固定在父母的底部。 WebView
在ImageView
之间对齐。它将它的高度调整到'ImageView'的高度。
尝试始终在XML和Java代码中保留某种结构,以便您和其他人可以在不开始哭泣的情况下查看它。