Android:顶部菜单栏+;滚动视图?
我是Android新手(用于使用Visual Studio开发…),到目前为止,我对布局有疑问: 我想做的是一个顶部有一个条的布局(只是为了放置一些按钮或额外的信息)和一个填充屏幕其余部分的滚动视图。 到目前为止,我就是这样做的:Android:顶部菜单栏+;滚动视图?,android,layout,Android,Layout,我是Android新手(用于使用Visual Studio开发…),到目前为止,我对布局有疑问: 我想做的是一个顶部有一个条的布局(只是为了放置一些按钮或额外的信息)和一个填充屏幕其余部分的滚动视图。 到目前为止,我就是这样做的: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:l
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Home" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="@android:color/white" >
<!-- I can put any button or text I want in here -->
</LinearLayout>
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="50dp"
android:background="@drawable/wallpaper" >
</ScrollView>
这正如我所期望的那样有效,但我的问题是,我是用正确的方式还是应该用更好的方式(最有效的方式)来做
提前感谢不建议使用绝对定位。例如,如果需要将高度从50dp增加到100dp,则必须在几个不同的位置更改此值 我至少知道两种改进布局的方法 1) 使用RelativeLayout的功能(
android:layout_下方=“@id/linearLayout1”
或其对应的layout_上方)
android:layout\u height=“0dip”这行可能看起来很奇怪。实际上,您可以使用match\u parent
,但如果您指定了android:layout\u weight
,Eclipse IDE会突出显示这一行,并建议使用0dip
我还将
android:fillViewport=“true”
添加到您的滚动视图中。它表示scrollview中的内容将扩展到全高(如果需要),您可以阅读有关此属性的信息,在scrollview中删除android:layout_marginTop=“50dp”,然后添加,android:layout_below=“@id/linearLayout1”
,而不是您做得很好的内容。
<RelativeLayout ...>
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="@android:color/white">
</LinearLayout>
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/linearLayout1"
android:fillViewport="true"
android:background="@drawable/wallpaper" >
</ScrollView>
</RelativeLayout>
<LinearLayout ...>
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="@android:color/white">
</LinearLayout>
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1.0"
android:fillViewport="true"
android:background="@drawable/wallpaper" >
</ScrollView>
</LinearLayout>