- 问题引入
设计布局时会用到scrollview的排版:ScrollView下面是按钮栏,ScrollView上面是说明,下面介绍一个方式来实现。
(有需要的可以直接新建一个xml文档,复制代码看看效果可以一试 )
1.用到相对布局,在ScrollView里放置自己的内容
2.整体为三段式,上面是标题,中间一个ScrollView,下面是按钮
如下代码:
<!--android:layout_gravity="start" 左侧划出,end 右侧-->
<RelativeLayout
android:layout_width="240dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/leftSide_bg_color"
android:layout_gravity="start">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:gravity="center"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/leftSide_btn_color"
android:text="历史记录"
/>
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/fileList"
android:layout_marginTop="55dp"
android:layout_marginBottom="55dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/sc_layout"
android:orientation="vertical"
>
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
>
<Button android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/leftSide_btn_color"
android:onClick="contactMe"
android:layout_gravity="bottom"
android:text="联系我" />
</LinearLayout>
</RelativeLayout>
- 说明:
核心代码为scrollview里的和上下两个部分设置的android:layout_height="50dp"
android:layout_alignParentBottom="true" android:layout_alignParentTop="true"
android:layout_marginTop="55dp"
android:layout_marginBottom="55dp"