我在 LinearLayout 中有一个 ScrollView,顶部有一个标题 LinearLayout。我已经给主要的 LinearLayout 一个背景。如果我保留 ScrollView 的背景,一切都会正常显示。但是如果我添加很多内容,那么 ScrollView 背景就会延伸。所以我想保持 ScrollView 透明。
但是如果我删除背景属性或者如果我尝试 android:background="@android:color/transparent" ScrollView 中的内容就会消失。我只能看到外部 LinearLayouts 的标题和背景。
这就是我想要的视图:
<Linear Layout with background image>
<Header Linear Layout>
</Header Linear Layout>
<ScrollView with no background>
<Layouts in Scroll View>
</ScrollView>
这是代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bg"
android:orientation="vertical" >
<include layout="@layout/topbar" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
style="@style/Labels"
android:text="@string/posts_add_postcontent" />
<EditText
android:id="@+id/postsAddContent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/posts_add_postcontent_h"
android:inputType="textMultiLine"
android:maxLength="3000"
android:minLines="3" />
</LinearLayout>
</ScrollView>
</LinearLayout>
注意:标题 LinearLayout 通过另一个文件包含:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/topbar"
android:layout_width="fill_parent"
android:layout_height="30dip"
android:background="@layout/bgtop_repeat"
android:orientation="horizontal"
android:paddingTop="2dip" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/app_name"
android:src="@drawable/cornerlogo" />
<Button
android:id="@+id/menubuton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="@drawable/menubutton" />
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@layout/headshadow_repeat"
android:orientation="horizontal" />
</LinearLayout>
提前致谢 :)